tapselj0@cs.man.ac.uk
thomas@resonance.org
DeadBull@gmx.net
Revision History | ||
---|---|---|
Revision 0.08 | 2002-07-11 | Revised by: jpt |
Revision 0.07 | 2002-02-27 | Revised by: jpt |
Revision 0.06 | 2001-09-08 | Revised by: jpt |
Revision 0.05 | 2001-09-07 | Revised by: jpt |
Revision 0.04 | 2001-09-01 | Revised by: jpt |
Revision 0.03 | 2001-07-06 | Revised by: jpt |
All of the authors are available on #debian on irc.opensource.net
John Tapsell (JohnFlux) is the official maintainer.
Email me (John Tapsell) for any query, flame, feedback, a date, etc.
Shamelessly stealing from David Ranch's work - <dranch@trinnet.net>.
This is NOT a replacement for the IP-Masquerading HOWTO - it is to complement it, and the two should be read side by side. I do not include things in here that are covered by the the other HOWTO, nor do I explain what it all means, or what it is all about. See http://ipmasq.cjb.net and the standard Masq-HOWTO for a much better guides.
This document describes how to enable the Linux IP Masquerade feature on a given Linux host. IP Masq is a form of Network Address Translation or NAT that allows internally networked computers that do not have one or more registered Internet IP addresses to have the ability to communicate to the Internet via your Linux boxes single Internet IP address.
This is all under the GNU Free Documentation License
This is intentionally short and to the point.
If you have a network, that you want to attach to the outside:
$> modprobe ipt_MASQUERADE # If this fails, try continuing anyway $> iptables -F; iptables -t nat -F; iptables -t mangle -F $> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 123.12.23.43 $> echo 1 > /proc/sys/net/ipv4/ip_forward |
$> modprobe ipt_MASQUERADE # If this fails, try continuing anyway $> iptables -F; iptables -t nat -F; iptables -t mangle -F $> iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE $> echo 1 > /proc/sys/net/ipv4/ip_forward |
$> iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $> iptables -A INPUT -m state --state NEW -i ! eth0 -j ACCEPT $> iptables -P INPUT DROP #only if the first two are succesful $> iptables -A FORWARD -i eth0 -o eth0 -j REJECT |
Or for a dial-up connection (with eth0 as the internal network card):
$> iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $> iptables -A INPUT -m state --state NEW -i ! ppp0 -j ACCEPT $> iptables -P INPUT DROP #only if the first two are succesful $> iptables -A FORWARD -i ppp0 -o ppp0 -j REJECT |
Compiling the kernel: (Use a 2.4.x kernel or greater)
You need the following support in the kernel:
$> modprobe ipt_MASQERADE |
Okay, I'm assuming that you have no other rules, so do:
$> iptables -F; iptables -t nat -F; iptables -t mangle -F |
Then if you have a static ip do (e.g. network card not using DHCP):
$> iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 123.12.23.43 |
or for dynamic (e.g. a modem - you have to call a number first):
$> iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE |
$> echo 1 > /proc/sys/net/ipv4/ip_forward |
First, allow any existing connections, or anything related (e.g. ftp server connecting back to you)
$> iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
$> iptables -A INPUT -m state --state NEW -i ! ppp0 -j ACCEPT |
$> iptables -P INPUT DROP #only if the first two are succesful |
And it should all work now. Don't forget to:
Allow through any services you do want the internet to see.
For an example, to allow access to your web server do:
$> iptables -A INPUT --protocol tcp --dport 80 -j ACCEPT $> iptables -A INPUT --protocol tcp --dport 443 -j ACCEPT |
To allow ident (For connecting to irc etc) do
$> iptables -A INPUT --protocol tcp --dport 113 -j ACCEPT |
Where eth0 is the external Internet card, and 123.12.23.43 is the external ip of that machine.
How do I list the rules I've got so far?
$> iptables -L $> iptables -t nat -L |
It won't resolve IP's! I'm typing 'www.microsoft.com' in and it says it can't find it!
It don't work! It doesn't like iptables / NAT / SNAT / MASQ
- Go get the latest kernel, and compile with iptables and full NAT support.
It don't work! The masquerading doesn't work at all! Die scum!
It don't work! I can't use the network at all and I hate you!
$> iptables -F $> iptables -t nat -F $> iptables -t mangle -F |
(all rules went bye-bye) then rerun the other iptables rules.
- Hmm, does "dmesg | tail" give any errors? or "cat /var/log/messages | tail" ? Like I care tho...
I don't get, it just ain't working!
- I dunno.. but you should be able to:
1) From the gateway machine, ping the outside 2) From the gateway ping your internal machines 3) From the internal machines ping the gateway |
How do I get it to only bring the ppp up on demand?
- Assuming your ISP gateway IP is say 23.43.12.43 for arguments sake, then append a line like this:
I hate doing this myself! I want a pre-made script and GUI and stuff.
- Sure: http://shorewall.sourceforge.net/
Eat your heart out!
Do I count Cable modems as static or dynamic IP's?
- Good question.. might as well make it dynamic.
Do I count DHCP network cards as static or dynamic IP's?
- They are dynamic.
How do I handle incomming services?
- Try forwarding or redirecting the IP ports - again make sure you firewall this if needed.
From the clients, I can ping the linux gateway's external IP address, but can't access the internet.
- Okay, try doing "rmmod iptable_filter" - more info on this as I get it.
- Make sure your not running routed or gated - to check run "ps aux | grep -e routed -e gated".
- Look at http://ipmasq.cjb.net
How can I view the connections establish? Something like netstat..
- Try cat /proc/net/ip_conntrack
I need more squid info and routing and stuff!
- Try the Advanced Routing HOWTO http://www.linuxdoc.org/HOWTO/Adv-Routing-HOWTO.html
This howto is crap! How do I yell at the guys who wrote this?
- Go to #debian on irc.opensource.net and find and locate JohnFlux. - Mail me (JohnFlux) at tapselj0@cs.man.ac.uk
This howto is crap! How can I see better versions?
- Try http://ipmasq.cjb.net
- Consult the LDP Masq-HOWTO.
What else are you working on?
Currently I'm writing a guide on linux on anti-missile-missiles-made-simple. There's no good guides on protecting your system from nuclear attacks for newbies. People seem to think its rocket science or something..