Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was able to get my server to forward connections on a certain port to a different IP, but when I add -d to specify an IP to froward from, It does not work. This is what I am trying,

iptables -t nat -A PREROUTING -d 173.208.230.107 -p tcp --dport 80
iptables -t nat -nvL-j DNAT --to-destination 38.105.20.226:80
.
It works fine without the -d. Here is my ifconfig dump:

em1       Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.106  Bcast:173.208.230.111  Mask:255.255.255.248
          inet6 addr: fe80::2a0:d1ff:feed:d054/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:100058 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18941701 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:12779711 (12.1 MiB)  TX bytes:825498499 (787.2 MiB)
          Memory:fbde0000-fbe00000

em1:9     Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.107  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:10    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.108  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:11    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.109  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

em1:12    Link encap:Ethernet  HWaddr 00:A0:D1:ED:D0:54
          inet addr:173.208.230.110  Bcast:173.208.230.111  Mask:255.255.255.248
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Memory:fbde0000-fbe00000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
share|improve this question
    
The proper flag is --dst –  Nathan C Jun 30 '13 at 22:17
    
@NathanC I place of -d? –  user1307079 Jun 30 '13 at 22:21
    
That's right. Should actually work. –  Nathan C Jun 30 '13 at 22:37
    
@NathanC When I add that in place of -d, I get bad argument. –  user1307079 Jun 30 '13 at 22:41
    
Shouldn't it be just iptables -t nat -A PREROUTING -d 173.208.230.107 -p tcp --dport 80 -j DNAT --to-destination 38.105.20.226:80? –  ott-- Jun 30 '13 at 23:11
show 3 more comments

1 Answer

I believe you only need on rule in the nat tables as well as an accept rule. Add you -d or -dst to the first rule.

iptables -t nat -p 6 --dport 80 -j DNAT --to-destination 38.105.20.226
iptables -A INPUT -p 6 --dport 25 -d 38.105.20.226 -j ACCEPT
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.