The following allows you to forward (NAT) traffic from an internal interface to an external interface (and back again ;]). In other words, creating a Gateway for a LAN (internal network).
Debian Based (apt-get)
- # apt-get install iptables
- # vi /etc/network/if-up.d/iptables
RedHat (rpm) Based
- # yum install iptables
- # vi /etc/sysconfig/iptables
- #!/bin/sh
- PATH=/usr/sbin:/sbin:/bin:/usr/bin
- # user defined
- WAN="eth0"
- LAN="eth1"
- # delete existing rules
- iptables -F
- iptables -t nat -F
- iptables -t mangle -F
- iptables -X
- # always accept loopback traffic
- iptables -A INPUT -i lo -j ACCEPT
- # allow established connections, and those not coming from the outside
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
- iptables -A INPUT -m state --state NEW ! -i $LAN -j ACCEPT
- iptables -A FORWARD -i $LAN -o $WAN -m state --state ESTABLISHED,RELATED -j ACCEPT
- # allow outgoing connections from the LAN side
- iptables -A FORWARD -i $WAN -o $LAN -j ACCEPT
- # masquerade out LAN interface
- iptables -t nat -A POSTROUTING -o $LAN -j MASQUERADE
- # do not forward from wan to lan
- iptables -A FORWARD -i $WAN -o $LAN -j REJECT
- # enable forwarding packets from interface to interface
- echo 1 > /proc/sys/net/ipv4/ip_forward
Debian Based (apt-get)
- # chmod +x /etc/network/if-up.d/iptables
- # sh /etc/network/if-up.d/iptables
RedHat (rpm) Based
- # service iptables restart
Note that this config does not give the ability to provide DHCP or DNS services to LAN clients.
You can easily tar up a Linux box and extract the files on a Linux partition (some version of ext). This can be great for making an image of a dying hard-drive or putting a hard-drive in another box, mounting it, and then making a backup (great if you need to mount read-only).
The following creates an archive, gzips the archive for greater compression, verbosely prints to the screen what is being backed up, preserves all permissions, and stores it in a file "device" /path/to/archive.tar.gz.
History lesson: most implementations of tar still default to using a tape device as output for the file stream!
- # tar -pczvf /path/to/archive.tar.gz \
- > --directory=/ \
- > --exclude=proc --exclude=sys --exclude=dev/pts \
- > .
To decompress the archive to the current working directory:
- # tar -pxzvf archive.tar.gz
- Tags
- ALIX (1)
- digitalfoo.net (2)
- embedded (6)
- FreeBSD (25)
- Java (1)
- Linux (20)
- misc (4)
- my projects (1)
- NanoBSD (3)
- opensource (5)
- perl (1)
- PHP (3)
- programming (7)
- security (4)
- Archives
- 2010
- June (5)
- July (2)
- April (6)
- March (2)
- May (1)
- August (2)
- 2009
- August (7)
- July (8)
- April (4)
- May (4)
- December (2)
- June (1)
- September (1)
- November (4)
- October (1)
- Web Tools
- Index
- dig-shovel Live
- SQL Injection Encoder
- Links
-

