Search This Blog

Monday, June 16, 2014

Ubuntu - setup port forwarding

To enable port forwarding on Ubuntu:

nano /etc/sysctl.conf

uncomment:
net.ipv4.ip_forward=1


Restart the system and check whether ip forwarding is enabled:
cat /proc/sys/net/ipv4/ip_forward

192.168.0.0   - NETWORK you're forwarding the traffic TO
10.0.0.0. - NETWORK you're forwarding the traffic FROM
IP - just your ip address in 10.0.0.0 network taken from eth0 interface


#!/bin/sh
IP="$(ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')"
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d 0.0.0.0/0 -j SNAT --to-source $IP
iptables -t nat -A POSTROUTING -s 192.168.0.123/32 -d 0.0.0.0/0 -j SNAT --to-source 192.168.0.100

#forward :5556 (10.0.0.0 network) -> :22 (192.168.0.0 network)
iptables -t nat -A PREROUTING -p tcp --dport 5556 -j DNAT --to 192.168.0.123:22
iptables -A FORWARD -p tcp -d 192.168.0.123 --dport 5556 -j ACCEPT



No comments:

Post a Comment

If you like this post, please leave a comment :)