NAT'ing a subnet for Internet access with IP tables
Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
NAT'ing a subnet for Internet access with IP tables
Hi all,
I have a debian box running as a gateway between my office network, the Internet and a remote subnet via a VPN. I have the office network and the remote subnet talking fine. The remote network is an Amazon VPC which means that for any machines in it to access the Internet, you have to NAT the traffic at my debian box. Internet requests hit the box but seem to get lost. I think it's a fairly simple solution but I'm knowledge of IP tables is limited (trying to learn).
# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT
# Allow established connections, and not those coming from the outside
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow outgoing connections from the LAN side.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# Don't forward from the outside to the inside.
iptables -A FORWARD -i eth1 -o eth1 -j REJECT
# Always accept loopback traffic
#iptables -A INPUT -i lo -j ACCEPT
# Allow established connections, and not those coming from the outside
#iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A INPUT -m state --state NEW -i ! eth1 -j ACCEPT
#iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow outgoing connections from the LAN side.
#iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# Don't forward from the outside to the inside.
#iptables -A FORWARD -i eth1 -o eth1 -j REJECT
that'd cover stuff going back to your ipsec addresses and if your not masq'ing the 10. address at the amazon or at the output of the vpn then you'll also need a
can you change that dst to host and also use -n so it stays in ip form? I'm interested in seeing if you are getting packets coming back. Doesn't seem like it's being masq'd though, i'd have expected to see two packets, one incoming and one outgoing only difference being ip change
That is not what I expected, we should see it twice at least if not 4 times, since the outbound packet is coming in and going out the same interface, and the reply would do the same. Do you have any iproute2 stuff setup like tables or rules that would alter the routing? might want to do a tcpdump on eth0 and see if the traffic is getting mis-directed out that interface.
I think I understand part of my misconception. The ipsec stuff should have its own interface I believe
if you do an ifconfig -a do you see an ipsec0 (or something like that)
So it might be we just need to adjust your routes. Can you currently get to your vpc from your internal stuff?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.