Linux How to setup multi homing network

by on November 8, 2006 · 12 comments· LAST UPDATED November 8, 2006

in , ,

Following tip is submitted by Raj.

Sample Scenario

If you have 2 NIC (network Lan card) each connected to different networks:
=> eth0: 192.168.1.0/24
=> eth1: 192.168.2.0/24

Consider above setup. Now if you want to route traffic to connected network only (eth0 and eth1) w/o setting Linux server as a router. This is generally called multi homing setup. You don't have to setup Linux box as a router to use multi homing :). Just assign as IP address to each NIC and you are done.

How do I configure Linux multi homing?

Just assign each interface IP address using ifconfig or use DHCP and multi homing will be turned on:
# ifconfig eth0 192.168.1.254 up
# ifconfig eth1 192.168.2.254 up

Commonly, most admin confuse the idea of multi-homing with the concept of routing or IP forwarding. Once two IP address assigned your system follows the default. No special configuration needed. Your multi-homing is up and running :).

Additional routing

You can turn on additional routing feature, with multi-homing. Just enable forwarding:
# echo 1 > /proc/sys/net/ipv4/ip_forwarding

If you reboot system you will lost additional routing setup. Add following line to your /etc/sysctl.conf file:
# vi /etc/sysctl.conf Add following line:net.ipv4.ip_forward = 1
Save and type command:# sysctl -p

But, what is the difference between routing and multi homing setup?

=> Multi homing route traffic to each connected network but no frames are forwarded between two networks.
=> Routing forward frames between two networks. See these (setup Linux as a router for DSL, T1 line etc) previous articles (setup vmware host router) on how to setup Linux as a router.

Updated for accuracy by nixCraft.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 12 comments… read them below or add one }

1 Sean November 8, 2006 at 1:17 pm

This one has me lost. First it says that it’s not necessary to route in order to multihome, then it turns on ip_forwarding which will turn the device into a router.

You can’t turn off routing. Every device routes — even a windows box has a routing table. Every time you send a packet the device has to decide whether to send it to a device on the local host, or choose a better route via a default router or something more specific.

If all you want to do is have a Linux box sit on two networks, then light up two NICs and turn OFF ip_forwarding. Look at the routing table, you’ll see two network entries for the two NICs plus any default routes.

Maybe this is just a language thing, but anything sitting on two networks, regardless of forwarding status, is multihomed. I think this is more properly called a “multi-homed bastion host” in firewall terminology.

Sean

Reply

2 nixCraft November 8, 2006 at 2:01 pm

Sean,

>Maybe this is just a language thing, but anything sitting on two networks, regardless of forwarding status, is multihomed

Agreed and it is default no need to turn on ip forwarding. After multi homing you can turn on additional routing with net.ipv4.ip_forward = 1.

In short it shows how to setup multi-homing networking by simply assigning an IP address and nothing special. I have updated post and title also.

Sorry for mixing up things. Next time before posting user submitted tips/how to; I will verify information.

Appreciate your post.

Reply

3 Aneesh November 24, 2006 at 11:28 pm

>=> Multi homing route traffic to each connected >network but no frames are forwarded between two >networks.
>=> Routing forward frames between two networks. See >these (setup Linux as a router for DSL, T1 line >etc) previous articles (setup vmware host router) >on how to setup Linux as a router.

Sorry, I can’t understand the defferences between the two. Can anyaone clarify please

Reply

4 nixCraft November 25, 2006 at 8:44 am

Aneesh,

Multi homing does not enables Linux act as a router.

If you need to Linux act as router just follow the link.

Reply

5 Sanjay June 7, 2007 at 5:44 am

Hi I have 2 NIC on linux box. Surprisingly I found that though having two different networks it is doing routing. How to solve this problem? Can anybody help me on this?

Reply

6 vipin October 11, 2007 at 1:44 pm

how can i make linux as router .I have install xorp and zebra.but unable to perform multihoming .can u pls help me for the same ?

Reply soon,
Vipin

Reply

7 George March 1, 2008 at 1:41 am

What do you guys think about this. I have a webserver that has 2 nic cards. I can connect to it throught the one nic, but the second nic is connected to another linux box with MySQL installed. I’m trying to connect to the MySQL database. How can I connect to it through the web server?

Reply

8 Schemie44 March 25, 2009 at 5:58 pm

Hi all

I also need to route between two networks. The first is 172.20.2(LAN) range the other is 192.168.1(ADSL). I need to come in from 192 which is setup with dyndns name ip’s going through to 172 ip.

What will be the easiest.

Reply

9 jameswatson3 April 1, 2009 at 7:54 pm

I have a very specific multihoming need, but I’m not sure if it will be met by default.

I have one sql database on network 1
I have 3 application servers multihomed on networks 1 and 2

Clients will access the application servers via dns records that will point to their addresses on network 2.

The Application servers and DB will communicate on network 1.

Will this happen by itself through standard tcp operations? Or will the traffic to the DB on network 1 travel out of the application server interface on network 2?

Reply

10 Andreas March 3, 2010 at 1:48 pm

By default, most server applications will bind to ANY address, which means it can be reached via any of the network interfaces (lo, eth0, eth1)

If this is not what you want, check each application for config settings like “bind” or “listen”. If the application does not support this, you can also use iptables to limit access to the application.

Reply

11 Shaheer May 16, 2011 at 5:41 am

I have a web site with ubuntu linux 10.10
my web sites is very slow
I want to increase response time of my web site specially my videos

should i use routing or multi homed?

Reply

12 Vishal Shinde June 9, 2014 at 12:44 pm

Can we assign 3 different ip Ranges in single Network Interface (eth0) ?

Reply

Leave a Comment

Previous post:

Next post: