{"id":352,"date":"2010-05-13T11:40:01","date_gmt":"2010-05-13T18:40:01","guid":{"rendered":"http:\/\/jim-zimmerman.com\/?p=352"},"modified":"2010-05-13T11:40:01","modified_gmt":"2010-05-13T18:40:01","slug":"how-to-nat-a-linux-virtual-interface","status":"publish","type":"post","link":"https:\/\/jim-zimmerman.com\/?p=352","title":{"rendered":"How to NAT a Linux virtual interface."},"content":{"rendered":"<p>I was able to use the following iptables configuration to NAT from a linux virtual interface (eth1:1) to an email\/web server on my LAN (192.168.0.x).  virt_ip_addr is the IP address I assigned to eth1:1, and 192.168.0.6 is the IP address of the server on my LAN.  This works with both INPUT and FORWARD chains set to DROP.<\/p>\n<p>This may not be the best solution, but it took quite a while to figure out how get something in place that works.<\/p>\n<p>######################<br \/>\n# nat PREROUTING Chain Rules<br \/>\n######################<\/p>\n<p>-A PREROUTING -d virt_ip_addr -p tcp &#8211;dport 25 -j DNAT &#8211;to 192.168.0.6:25<br \/>\n-A PREROUTING -d virt_ip_addr -p tcp &#8211;dport 80 -j DNAT &#8211;to 192.168.0.6:80<\/p>\n<p>######################<br \/>\n# nat POSTROUTING Chain Rules<br \/>\n######################<\/p>\n<p>-A POSTROUTING -o eth1 -j SNAT &#8211;to-source virt_ip_addr<\/p>\n<p>######################<br \/>\n# filter FORWARD Chain Rules<br \/>\n######################<\/p>\n<p>-A FORWARD -p tcp -i eth0 -o eth1 -s 192.168.0.6 -m multiport &#8211;sports 25  -j ACCEPT<br \/>\n-A FORWARD -p tcp -i eth1 -o eth0 -d 192.168.0.6 -m multiport &#8211;dports 25  -m state &#8211;state NEW -j ACCEPT<br \/>\n-A FORWARD -p tcp -i eth1 -o eth0 -d 192.168.0.6 -m multiport &#8211;dports 25  -j ACCEPT<\/p>\n<p>-A FORWARD -p tcp -i eth0 -o eth1 -s 192.168.0.6 -m multiport &#8211;sports 80  -j ACCEPT<br \/>\n-A FORWARD -p tcp -i eth1 -o eth0 -d 192.168.0.6 -m multiport &#8211;dports 80  -m state &#8211;state NEW -j ACCEPT<br \/>\n-A FORWARD -p tcp -i eth1 -o eth0 -d 192.168.0.6 -m multiport &#8211;dports 80  -j ACCEPT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was able to use the following iptables configuration to NAT from a linux virtual interface (eth1:1) to an email\/web server on my LAN (192.168.0.x). virt_ip_addr is the IP address I assigned to eth1:1, and 192.168.0.6 is the IP address of the server on my LAN. This works with both INPUT and FORWARD chains set [&#038;hellip<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[76,48,77],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-documentation","tag-iptables","tag-linux","tag-virtual-interface"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=352"}],"version-history":[{"count":1,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=\/wp\/v2\/posts\/352\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jim-zimmerman.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}