Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

To clarify my question...

I am wondering how does the Linux kernel route packets on a multi-home host?

With 'multi-home', I mean the host has multiple NICs to send packets, for example my Debian in Virtualbox has two NICs.

eth0 provides the NAT support. I don't know how Virtualbox manages to do that. I mean there isn't any virtual NIC in my windows host whose IP is 10.0.2.x.

eth1 provides the host-only support. I use this small network to learn TCP/IP protocol and do some small experiments. I manually configure it to IP address, gateway, the latter IP address is the Virtualbox virtual NIC IP address.

host operating system I use ADSL to connect to the Internet and get a random IP address,

So the question comes out, how does the linux kernel route IP packets? I mean if I have run the following commands, I am not able to connect to the Internet.

ifup eth0
ifup eth1

that ping would return no response.

So is it that the after setting up the eth1, the kernel would use eth1 as the default NIC, which is in the host-only network, to send IP packets? As a result, in Debian, I cannot connect to the outside internet?

Another simple question is, as eth1 now is the default NIC, will the Linux kernel try to use the eth1 NIC to send packets if eth0 has failed to find an available route entry?
If it will, then how to configure it?

Here is my network configuration of Debian Linux in Virtualbox.

eth0  Link encap:Ethernet  HWaddr 08:00:27:ec:d9:bb  
              inet addr:  Bcast:  Mask:
              inet6 addr: fe80::a00:27ff:feec:d9bb/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:1690 errors:2 dropped:0 overruns:0 frame:0
              TX packets:1129 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:2276172 (2.1 MiB)  TX bytes:62647 (61.1 KiB)
              Interrupt:11 Base address:0xd020 

eth1      Link encap:Ethernet  HWaddr 08:00:27:ae:e1:69  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::a00:27ff:feae:e169/64 Scope:Link
          RX packets:48 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5985 (5.8 KiB)  TX bytes:1334 (1.3 KiB)
          Interrupt:10 Base address:0xd240 

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)

and the route table follows:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 eth0   U         0 0          0 eth1         UG        0 0          0 eth1         UG        0 0          0 eth0


share|improve this question
can you plz post your routing table? In your debian use: netstat -rn – evildead Oct 25 '09 at 1:00
up vote 0 down vote accepted

I'm not sure I understand correctly the problem but do a 'echo 1 > /proc/sys/net/ipv4/ip_forward' to enable routing. Make it permanent by editing /etc/sysctl.conf . When this is set to 1 (enabled) Linux will forward packets received from on one ethernet interface to another - it will act as a router.
If you have a dual-home machine - two ways to get out on the internet - you can't use both uplinks with just two default gateways installed... What you can do is select the primary default gateway , let's say and then select some networks you want to get trough the secondary link:
ip route add default via
ip route add 221.x.x.x/24 via
ip route add via

share|improve this answer
@Lorinescu,you are enough amazing to understand what I want to ask.Sorry for my bad english,anyway. – Jichao Oct 25 '09 at 7:26

Your question is sort of confusing but let me give it a shot.

First, if you want to have a simple NAT/masquerading router, there are some simple, adaptable tutorials on how to do this with netfilter (iptables). It can be deceptively simple to enable this behavior. Googling "linux nat" or "linux masquerade" will help.

edit: throwing the basic commands in for good measure. Be sure you know which interface is which!

/sbin/iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
/sbin/iptables -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT

Otherwise you should just be able to use the route command to delete the 'extra' gateways and force all traffic out through eth1 if that's your goal (don't need eth0 at all in this scenario if I understand you right.)

route del gw eth0

Should do the trick on the last scenario. (If I understand you correctly, which I may not.)

Hope that helps.

share|improve this answer
To clarify, the second scenario I understood there is just a "useless" NIC, but if that NIC is connected to another actual LAN, then the first scenario definitely applies. – Sam Halicke Oct 25 '09 at 1:35
@serverninja,thanks for your kindly reply,I have learnt a lot. – Jichao Oct 25 '09 at 7:23

You have two default routes. I've only ever used one at a time, but I imagine two wouldn't be a problem --- as far as I know, the routing table is sorted by specificity (number of bits in the destination subnet mask, ascending) and maybe MTU (though I don't think so on Linux). The first matching default route in the sorted list would then be used.

Try removing one of the default routes anyway (route del... as others have mentioned, or ip route del...).

Otherwise... why is your ping getting "no response"? That sounds like a firewall issue. It MIGHT be that linux is automatically doing a load-balancing/round-robin thing with the two default routes, but I've never heard of Linux doing that, and it could create problems for some protocols, so I doubt it.

If you're having routing issues, ping should probably say "no route to host" or something like that. No response is different. Make sure ping is figuring out the IP from the hostname OK. If not, it's a DNS issue. If so, look to your firewall -- iptables -L -n -v will give you any rules, and how many times the rules have been hit. If a rule increases as often as your pings, that's likely to be the problem. Otherwise, examine the packets leaving and entering the machine with wireshark.

share|improve this answer

so, let me explain you some basics on your example. You have 2 Nics (virtual or not doens't matter). Both are in seperate Networks. and

The first two entries in your routing table shows they have no special gateway ( ant last column shows at which NIC they are connected.

Then there is an mistake in the routing table. You have two entries in for the default gateway. You can only have one real default gateway. Normally the IP Packets are sent to the first default gw found in the routing table. (I guess in your case its the wrong one)

I dont know how exactly the NAT thing works ( I ever use bridged Networking). So you have two options. Set the default gateway to the IP Adress of your REAL Machines IP Adress. E.g. if your Machine outside of your virtual Box has the IP set yout default gateway to (In NAT Enviroment you have to setup your Machine outside of your virtual Box to support that, ipfilter must be setup right and routing Packets between Interfaces must be enabled echo 1 > /proc/sys/net/ipv4/ip_forward).

If you use a bridged Setup, your Machine has direct connection to your Router, which is connected to the internet. Than you only have to setup an ip Adress is this Network and setup your default gateway to the ip of your router. e.g. VBOX ------- MACHINE OUTSIDE VBOX ------ Router connected to Internet

Than your gateway will be

share|improve this answer

Your Answer


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.