0

I know there are a lot of questions about this, but I still struggling to get it working.

I have a firewall which has 3 external IPs. (IPs have been changed randomly for security)

eth0      Link encap:Ethernet  HWaddr 50:46:5d:64:ed:e4  
          inet addr:51.215.232.147  Bcast:51.215.232.159  Mask:255.255.255.240
          inet6 addr: fe80::5246:5dff:fe64:ede4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:70219084 errors:0 dropped:17443 overruns:0 frame:0
          TX packets:63956103 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:51508818511 (51.5 GB)  TX bytes:27933240304 (27.9 GB)

eth0:1    Link encap:Ethernet  HWaddr 50:46:5d:64:ed:e4  
          inet addr:51.215.232.148  Bcast:51.215.232.159  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr 50:46:5d:64:ed:e4  
          inet addr:51.215.232.150  Bcast:51.215.232.159  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

And I have these simple rules:

# Generated by iptables-save v1.4.10 on Sat Mar  3 14:48:42 2012
*filter
:INPUT ACCEPT [13766:4986720]
:FORWARD ACCEPT [992:122980]
:OUTPUT ACCEPT [11894:5582822]
-A FORWARD -s 172.16.0.0/16 -o eth0 -j ACCEPT 
-A FORWARD -d 172.16.0.0/16 -i eth0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 
COMMIT
# Completed on Sat Mar  3 14:48:42 2012
# Generated by iptables-save v1.4.10 on Sat Mar  3 14:48:42 2012
*nat
:PREROUTING ACCEPT [77:8206]
:INPUT ACCEPT [48:6367]
:OUTPUT ACCEPT [55:3300]
:POSTROUTING ACCEPT [55:3300]
-A POSTROUTING -s 172.16.0.0/16 -o eth0 -j MASQUERADE 
-A POSTROUTING -s 10.10.0.0/16 -o eth0 -j MASQUERADE 
-A POSTROUTING -s 10.1.0.0/16 -o eth0 -j MASQUERADE 
COMMIT
# Completed on Sat Mar  3 14:48:42 2012

So I want to forward everything from 51.215.232.150 to internal IP 172.16.5.218.

So I thought this would work:

iptables  -t nat -I PREROUTING -p tcp -d 51.215.232.150 -j DNAT --to 172.16.5.218

But alas no.

Thanks in advance. Edward

1
  • Please do not use IP addresses that do not belong to you. IANA has set aside three IPv4 ranges (192.0.2.0/24, 198.51.100.0/24, and 203.0.113.0/24) and on IPv6 range (2001:db8::/32) for examples. You should use addressing from those ranges to obfuscate your real addressing so that we know they are example addresses, not addresses that belong to someone else.
    – Ron Maupin
    Nov 15, 2021 at 0:16

1 Answer 1

0

Normally I would say that you need a corresponding FORWARD rule to actually allow the traffic through the FILTER table:

iptables  -A FORWARD -p tcp -d 172.16.5.218 -j ACCEPT

But your policy on the FORWARD table is already ACCEPT and there are no REJECT or DROP rules so it should go through OK.

Try adding a TRACE rule to see where the packet is going:

iptables -t raw -I PREROUTING -p tcp -d 51.215.232.150 -j TRACE

Also, how are you testing? Can you see the traffic actually reaching the box?

tcpdump -lnn -i eth0 host 51.215.232.150

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .