Difference between revisions of "IP Forwarding and iptables configuration"
From MyWiki
Line 15: | Line 15: | ||
'''Forwarding traffic from one port to another machine and port''' <br> | '''Forwarding traffic from one port to another machine and port''' <br> | ||
− | + | iptables -t nat -A PREROUTING -p tcp --dport 1111 -j DNAT --to-destination 2.2.2.2:1111<br> | |
and finally, we ask IPtables to masquerade:<br> | and finally, we ask IPtables to masquerade:<br> | ||
iptables -t nat -A POSTROUTING -j MASQUERADE <br> | iptables -t nat -A POSTROUTING -j MASQUERADE <br> |
Revision as of 20:53, 19 February 2016
Forwarding must be enabled
root@raspbx:~# cat /proc/sys/net/ipv4/ip_forward
0
root@raspbx:~# sysctl -w net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1
root@raspbx:~# cat /proc/sys/net/ipv4/ip_forward
1
root@raspbx:~#
Routing and Masquerading
iptables --table nat --append POSTROUTING -o ppp0 -j MASQUERADE
iptables --append FORWARD -i eth0 -j ACCEPT
Forwarding traffic from one port to another machine and port
iptables -t nat -A PREROUTING -p tcp --dport 1111 -j DNAT --to-destination 2.2.2.2:1111
and finally, we ask IPtables to masquerade:
iptables -t nat -A POSTROUTING -j MASQUERADE