Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 , I started a DHCP server that is on eth0 ( because it wont use eth0:0) and that's giving out addresses between and 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. Need help..

share|improve this question

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

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

I would make use of iproute2 using the ip cmd. andys.org.uk/bits/2010/02/24/iproute2-life-after-ifconfig – slm May 18 '14 at 18:12
very good guide to transform your ubuntu into a router – Kiwy May 18 '14 at 21:37
You'd never use an aliased interface (eth0:0) for a real router. You'd use another LAN card/NIC. If this is just for learning/testing sake that's OK. – Matt H May 18 '14 at 22:05
I think you may be running a rogue DHCP server on eth0, and that could cause problems. – 200_success May 19 '14 at 4:26

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.

share|improve this answer

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.

share|improve this answer
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

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
share|improve this answer

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 
share|improve this answer

Your Answer


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