Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
I have an old(er) linksys WRT54G "router" (we all know that it's actually a nat box/switch/ap in a package that says router, but I'll use the marketing speak for the purposes of this post and call it a "router").
I also have 5 static IP's assigned to me by my ISP which all share one port on the modem. To make this happen I flashed the Thibor15c firmware into the "router" and cobbled together this little firewall script:
Code:
iptables -t nat -I PREROUTING -d EXT.IP.ADDY -j DNAT --to-destination INT.IP.ADDY
iptables -t nat -I POSTROUTING -s INT.IP.ADDY -j SNAT --to-source EXT.IP.ADDY
...which I repeated 4 times for 4 devices and used the 5th IP for the NAT box itself...
This worked great for a long time, while all of the external IP's were on the same subnet.
I recently switched ISP's, and my new static IP addresses are on 5 different subnets! Is there a way for me to specify the gateway on each line of that script?
iptables -t nat -I PREROUTING -d EXT.IP.ADDY -j DNAT --to-destination INT.IP.ADDY
iptables -t nat -I POSTROUTING -s INT.IP.ADDY -j SNAT --to-source EXT.IP.ADDY
...which I repeated 4 times for 4 devices and used the 5th IP for the NAT box itself...
This worked great for a long time, while all of the external IP's were on the same subnet.
I recently switched ISP's, and my new static IP addresses are on 5 different subnets! Is there a way for me to specify the gateway on each line of that script?
TIA,
J
NAT examines source IP and destination IP, it doesn't care about GW. So I think you can't check GW with NAT iptables module.
There are 5 external addresses on the WAN port of my "router". My script is using iptables to route those external addresses to 5 devices on the internal network. i.e. - this allows 2 workstations, a VPN host, a web/ftp server, and the nat box to each have its own external address, but all be on the same internal network/subnet.
My new problem is that the external addresses that my new ISP gave me are all on different subnets. I'm trying to handle this without having to drop the funds on a real-deal enterprise router.
To choose GW you need specify or explain to your router which GW to use for which destination.
NAT can change source IP, but it can't GW, because POSTROUTING is located after router, which chooses a GW.
You can try to associate the destination IP and gateway you want router to use/choose.
For example:
Code:
Destination Gateway Genmask Flags Metric Ref Use Iface
<mail server IP> <Desired GW> 255.255.255.255 U 0 0 0 ethX
If I understand you (and the other poster) right, PREROUTING and POSTROUTING are just not going to work. How and where do I make this specification then? Am I still working in the firewall script? Should I still be using preroute and postroute but specify the gateways in the startup script? Should I still be trying to do this with IPTABLES at all?
I'm grasping here, but should I put a few ifconfig strings in the startup script to associate the right gateways with each address? If I am on the right track, would you mind helping me out with the syntax, please?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.