简体   繁体   中英

iptables NAT remote ip to local

We have an EC2 server with 400 domains / vhosts on amazon's ec2. We use just one single public IP (1.1.1.1). Because of NAT we use the internal IP (10.1.2.0) in apaches config. So far so good.

Some cronscripts need to access the hosted domains but these cronjobs are also hosted on the same machine. Because of the NAT it's not possible to reach any of the hosted domains by hostname from the localhost. I've been trying to figure it out with iptables, but no luck

Looks like this is not working:

iptables -t nat -A PREROUTING -p tcp -d 1.1.1.1 -j DNAT --to 10.1.2.0

Any thoughts? Of course i can add al 400+ domains to /etc/hosts, but then i have to keep track of all the domains and it isnt very flexible. Ofcourse we can also change the way the cronjobs are working, but we need a 'quick' fix right now. Is this possible with iptables?

If I understood you right, you want to redirect traffic originating from the same machine. In this case you should use OUTPUT chain. Packets from local processes do not pass through POSTROUTING chain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM