Andy Wilson - IP Masquerade - February 2000 IP Masquerade Andy Wilson UNC Chapel Hill February 16, 2000
Andy Wilson - IP Masquerade - February 2000 Outline What’s IP Masquerade?What’s IP Masquerade? Why would you want it?Why would you want it? How it worksHow it works What you’ll needWhat you’ll need Setting upSetting up TestingTesting
Andy Wilson - IP Masquerade - February 2000 What’s IP Masquerade? Network Address Translation (NAT) under LinuxNetwork Address Translation (NAT) under Linux –almost, but not quite, the same as firewalling Allows several networked computers to talk to the Internet through a single IP addressAllows several networked computers to talk to the Internet through a single IP address
Andy Wilson - IP Masquerade - February 2000 Why would you want it? Connectivity for a home networkConnectivity for a home network –Many ISPs only allow one IP address SecuritySecurity –Hide machines containing sensitive information –Allow access only to specific services on specific machines
Andy Wilson - IP Masquerade - February 2000 How it works: Network Structure Frodo Bilbo Pippin Gateway PPP: Enet: Internet Home Network
Andy Wilson - IP Masquerade - February 2000 How it works: Example slashdot.org Gateway PPP: Enet: Frodo New connection: :1234 to :80
Andy Wilson - IP Masquerade - February 2000 How it works: Example Gateway PPP: Enet: Frodo Connected: :1234 to :80 New connection: :5432 to :80 Port map: > Frodo:1234
Andy Wilson - IP Masquerade - February 2000 How it works: Example Gateway PPP: Enet: Frodo Connected: :1234 to :80 Connected: :5432 to :80 Port map: > Frodo:1234 Connection opened: from :5432 to :80
Andy Wilson - IP Masquerade - February 2000 How it works: Example Gateway PPP: Enet: Frodo Connected: :1234 to :80 Data received: :5432 from :80 Port map: > Frodo:1234 Connection opened: from :5432 to :80
Andy Wilson - IP Masquerade - February 2000 How it works: Example Gateway PPP: Enet: Frodo Data received: :1234 from :80 Data received: :5432 from :80 Port map: > Frodo:1234 Connection opened: from :5432 to :80
Andy Wilson - IP Masquerade - February 2000 What you’ll need Two computers (at least)Two computers (at least) Local LANLocal LAN Outside connection (ISP)Outside connection (ISP) One machine running kernel 2.2.x (x > 13)One machine running kernel 2.2.x (x > 13) – is possible but not recommended »(see HOWTO for details)
Andy Wilson - IP Masquerade - February 2000 Setting Up: Overview Build a kernel with the right options enabledBuild a kernel with the right options enabled Configure your LANConfigure your LAN Configure your ISP connectionConfigure your ISP connection Configure IPCHAINSConfigure IPCHAINS Reboot and testReboot and test CelebrateCelebrate
Andy Wilson - IP Masquerade - February 2000 Setting Up: Compiling the Kernel If this is your first time compiling a kernel:If this is your first time compiling a kernel: DON’T PANIC.DON’T PANIC. Read the Kernel-HOWTO for instructions. It’s quite simple. After that...Read the Kernel-HOWTO for instructions. It’s quite simple. After that...
Andy Wilson - IP Masquerade - February 2000 Setting Up: Kernel Options Enable incomplete/development drivers Enable incomplete/development drivers Enable networking, firewalls, TCP/IP Enable networking, firewalls, TCP/IP Enable firewalling (again) Enable firewalling (again) Enable masquerading, always defragment Enable masquerading, always defragment Enable ICMP masquerade Enable ICMP masquerade Enable IP forwarding Enable IP forwarding Disable ipautofw Enable TCP syncookies Enable TCP syncookies Enable /proc filesystem Enable /proc filesystem Enable PPP (if your ISP connection is a dialup) Enable PPP (if your ISP connection is a dialup) Don’t forget a driver for your Ethernet card! Don’t forget a driver for your Ethernet card!
Andy Wilson - IP Masquerade - February 2000 Setting Up: LAN configuration IANA Reserved Network NumbersIANA Reserved Network Numbers – /8 – /16 – /16 Select IP addresses from one of these blocksSelect IP addresses from one of these blocks Default gateway should be firewall machineDefault gateway should be firewall machine Consider running a nameserver on firewallConsider running a nameserver on firewall
Andy Wilson - IP Masquerade - February 2000 Example Network Frodo Bilbo Pippin Gateway PPP: Enet: Internet Home Network
Andy Wilson - IP Masquerade - February 2000 Setting Up: IPCHAINS Create /etc/rc.d/rc.firewall (or add to rc.local)Create /etc/rc.d/rc.firewall (or add to rc.local) #!/bin/sh # Enable IP forwarding (hopefully disabled at boot by default) echo “1” > /proc/sys/net/ipv4/ip_forward # Set masquerade timeouts (2 hours for TCP, 10sec for connection closing, # 160 sec for UDP (like ICQ)) /sbin/ipchains -M -S # Set up masquerade policies # by default, deny everything /sbin/ipchains -P forward DENY # but masquerade for just this one network /sbin/ipchains -A forward -s /24 -j MASQ
Andy Wilson - IP Masquerade - February 2000 Setting Up: IPCHAINS Configure connection to the outside world as usualConfigure connection to the outside world as usual –diald is useful! Make sure rc.firewall gets run at boot timeMake sure rc.firewall gets run at boot time –chmod 700 /etc/rc.d/rc.firewall –in /etc/rc.d/rc.local: »/etc/rc.d/rc.firewall
Andy Wilson - IP Masquerade - February 2000 Testing From firewall:From firewall: –Connect to ISP and ping outside world –Ping a machine inside your network From your network:From your network: –Ping firewall machine –Ping outside world by IP number –Ping outside world by name –Visit your favorite Web site
Andy Wilson - IP Masquerade - February 2000 Learning More IP Masquerade Resource:IP Masquerade Resource: – HOWTO (at (at –Kernel –IP masquerade –Networking overview –Ethernet