{"id":774,"date":"2011-12-05T13:50:02","date_gmt":"2011-12-05T18:50:02","guid":{"rendered":"http:\/\/scripts.mit.edu\/~zong\/wpress\/?p=774"},"modified":"2011-12-08T07:27:06","modified_gmt":"2011-12-08T12:27:06","slug":"connection-sharing-on-linux","status":"publish","type":"post","link":"https:\/\/blog.yhuang.org\/?p=774","title":{"rendered":"connection sharing on linux"},"content":{"rendered":"<p>To turn a linux box with two network interfaces into a NAT router with the most basic functions, four separate changes are required. This is more complicated than it needs to be. For future reference:<\/p>\n<p>1. Enable packet forwarding in the &#8220;registry&#8221;:<br \/>\nEdit <em>\/etc\/sysctl.conf<\/em> to add<br \/>\n<em>net\/ipv4\/ip_forward=1<\/em> then<br \/>\n> <em>sysctl -p \/etc\/sysctl.conf<\/em><\/p>\n<p>2. Set address sharing for outbound traffic and poke holes in the firewall:<br \/>\nAssume eth0 is the WAN-facing interface and eth1 is the LAN-facing interface, then<br \/>\n> <em>iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE<\/em><br \/>\n> <em>iptables -t filter -A FORWARD -i eth1 -o eth0 -j ACCEPT<\/em><br \/>\n> <em>iptables -t filter -A FORWARD -i eth0 -o eth1 -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<\/em><br \/>\n> <em>\/etc\/init.d\/iptables save active<\/em><br \/>\n> <em>\/etc\/init.d\/iptables restart<\/em><br \/>\nTurn on the iptables service in <em>sysvconfig<\/em><\/p>\n<p>3. Enable automatic serving of dynamic LAN IP&#8217;s:<br \/>\nAssume 10.0.0.x is the LAN-side subnet and 192.168.0.1 is the WAN-side DNS server or gateway, then<br \/>\nEdit <em>\/etc\/dhcp3\/dhcpd.conf<\/em> to add, e.g.<br \/>\n<em>subnet 10.0.0.0 netmask 255.255.255.0 {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; range 10.0.0.2 10.0.0.10;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; option routers 10.0.0.1;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; option domain-name-servers 192.168.0.1<br \/>\n}<\/em><br \/>\n> <em>\/etc\/init.d\/dhcp3-server restart<\/em><\/p>\n<p>4. Set the LAN-facing interface to be on the LAN-side subnet:<br \/>\nAssume 10.0.0.1 is the LAN-side address of connection sharing machine, then<br \/>\nEdit <em>\/etc\/network\/interfaces<\/em> to add<br \/>\n<em>auto eth1<br \/>\niface eth1 inet static<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; address 10.0.0.1<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; netmask 255.255.255.0<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; gateway 192.168.0.1<\/em><br \/>\n> <em>\/etc\/init.d\/networking restart<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To turn a linux box with two network interfaces into a NAT router with the most basic functions, four separate changes are required. This is more complicated than it needs to be. For future reference: 1. Enable packet forwarding in the &#8220;registry&#8221;: Edit \/etc\/sysctl.conf to add net\/ipv4\/ip_forward=1 then > sysctl -p \/etc\/sysctl.conf 2. Set address [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2592,2583,1104,2586,2589],"class_list":["post-774","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-conf","tag-connection","tag-edit","tag-eth","tag-init"],"_links":{"self":[{"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=\/wp\/v2\/posts\/774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=774"}],"version-history":[{"count":0,"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=\/wp\/v2\/posts\/774\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yhuang.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}