0

So I have been trying to convert my linux box which is running Mint into an router. eth0 has a public address that has 71.xx.xx.xx for an IP addr. I created an eth0:0 and set it an IP address , 10.0.0.100. I started a DHCP server that is on eth0 ( because it wont use eth0:0) and that's giving out addresses between 10.0.0.101 and 10.0.0.200. I can ping between eth0 and eth0:0 on the same machine. I have a another laptop connected to the linux via a switch and its able to receive an ip addr via the DHCP server. Problem is how do I route traffic from and to eth0:0 to eth0 and vice versa so that computers on the private network that is 10.0.0.x can access internet via the static IP on eth0.

migrated from serverfault.com May 19 '14 at 1:04

This question came from our site for system and network administrators.

3

You need at lease 2 interfaces do be able to do forwarding by routing mechanism. Those interfaces should be wither physical ones (think eth0 eth1), vlan (eth0.1 eth0.2), vpn (tun), bridge (br0), bond... but not aliases. Aliases are just a way to attach more IPs to the same interface.

However as you have private IP addresses, you can do SNAT and DNAT to forward IP traffic using the Netfilter (iptables) firewall rules.

1

First of all enable forwarding:

   echo 1 > /proc/sys/net/ipv4/ip_forward

That should be all you need, since your "gateway" can see both sides. If not you might need to look at natting, since the traditional approach of using iptables to allow forwarding won't work with only a single NIC.

  • 1
    Also, don't forget to check any iptables rules is filtering your traffic (iptables -L -vnc is a good way to check, look at the package count), as iptables work only with the physical ethernet (eth0) and not with the virtual ones (eth0:0) and you may have applied wrong rules thinking it would work. – higuita May 18 '14 at 21:57
0

Try with

# Ensure that ip forwarding is active
echo 1 > /proc/sys/net/ipv4/ip_forward
# Masquerade local net with public IP
iptables -I POSTROUTING -t nat -o eth0 -j SNAT --to-source 71.xx.xx.xx
-1

First enable forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

Then try this:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

iptables -A FORWARD -i eth0 -o eth0:0 -m state --state RELATED,ESTABLISHED -j ACCEPT

iptables -A FORWARD -i eth0:0 -o eth0 -j ACCEPT 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy