I want to switch primary network interface of my Ubuntu machine, I referenced this: http://www.cyberciti.biz/faq/linux-setup-default-gateway-with-route-command/.

Here is my setting for experiments: I use a router to provide connection for both wlan0 and eth0, with different IP ( and respectively, gateway Normally eth0 is the default one, so I do:

route delete gw eth0
route add gw wlan0

Interestingly, although is now the dominant IP, but I see incoming traffic captured in eth0 with as destination IP, and outbound packet in wlan0 as expected.

Why this is happening? And what is the correct way to do that interface switching?



By default, Linux uses the "weak host" model on IPv4; that is, it answers ARP requests for any address assigned to the system, even if they came through a different interface.

So when the router broadcasts an ARP request for .115, your host receives it through both interfaces, sends answers via both, and the router receives the answer over Ethernet first.

There are two sysctl tunables to change this behavior:

  • net.ipv4.conf.*.arp_filter

    Described in Documentation/networking/ip-sysctl.txt:1032.

    1 - Allows you to have multiple network interfaces on the same subnet, and have the ARPs for each interface be answered based on whether or not the kernel would route a packet from the ARP'd IP out that interface (therefore you must use source based routing for this to work).

  • net.ipv4.conf.*.arp_ignore

    Described in Documentation/networking/ip-sysctl.txt:1082.

    1 - reply only if the target IP address is local address configured on the incoming interface

For example, you could set the following in sysctl.d:

net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.all.arp_ignore = 1

(Note that I'm not completely sure which setting is suitable in what situation.)

  • I used the two nrp_ignore one, they seem more suitable, but after I switched, my router often have trouble to send packet back to me. Requests are sent out normally on wlan0, but never coming back. – Lingyuan He Apr 1 '15 at 16:10

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.