# multiple global IP-addresses

## bytelab

Hi everyone!

I have a litte issue which is probably easy to solve, but since I'm not very experienced with linux networking I could use some help.

A have a server running at home and from my ISP I am able to recieve up to five dynamic ip addresses via dhcp. My server has 2 network interfaces which are configured to be set up via dhcp. This works fine, they all get an IP when I start my box. Currently I am running a webserver and a battlefield 2 game server. The reason why I have two network interfaces is because with this setup I will get two different IP addresses from my ISP, one for each nic. This way I want the webserver to be reachable on one address and the game server on the other. Actually I want the webserver, sshd, lynx, emerge, ping (everything that uses the internet) and all other services except the game server to use the first of my nics, and the game server will serve alone on the other.

The problem with this setup is that some how I am unable to get any internet connectivety at all from my server. If I pull the cable on one of the nics everything works fine, but with both connected, nothing... Has this something todo with Linux not knowing which nic to use when they both are connected? I.e if I start lynx and try to access www.yahoo.com from my server, what tells linux and lynx which nic it should use to serve my request ?

I know that many applications like apache, sshd and such has some sort of address bind settings in their configuration and I have tried to use that. But I dont know how I set this up for other applications like emerge, lynx or ping. Is there a way to make my first nic "default", so that all internet trafic goes throug this (like if there were no second nic) except the applications I bind to another address? 

here is my /etc/conf.d/net:

config_eth0=( "dhcp" )

dhcp_eth0="nodns nontp nonis -t 10"

config_eth1=( "dhcp" )

dhcp_eth1="nodns nontp nonis -t 10"

and here is the output from ifconfig with both nics connected (I did change the addresses manually..):

eth0      Link encap:Ethernet  HWaddr 00:02:E3:04:02:A2

          inet addr:83.xxx.xxx.xxx  Bcast:83.xxx.xxx.xxx  Mask:255.255.255.192

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:16738664 errors:93 dropped:0 overruns:0 frame:249

          TX packets:13270849 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:2591249664 (2471.2 Mb)  TX bytes:3828889182 (3651.5 Mb)

          Interrupt:145 Base address:0x6000

eth1      Link encap:Ethernet  HWaddr 00:09:5B:8C:EE:C1

          inet addr:83.xxx.xxx.xxx  Bcast:83.xxx.xxx.xxx  Mask:255.255.255.192

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:28326824 errors:0 dropped:0 overruns:0 frame:0

          TX packets:41205776 errors:1 dropped:0 overruns:1 carrier:1

          collisions:0 txqueuelen:1000

          RX bytes:548448266 (523.0 Mb)  TX bytes:3127531285 (2982.6 Mb)

          Interrupt:113 Base address:0x8000

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:298982 errors:0 dropped:0 overruns:0 frame:0

          TX packets:298982 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:98855522 (94.2 Mb)  TX bytes:98855522 (94.2 Mb)

Very thankful for replies!

/bytelab

----------

## minskpower

I'm sorry but I fail to see the reason of having 2 NIC's.

Maybe I could help you, but please explain to me why don't you use one NIC with multiple aliases. Is there something to do with your ISP preventing you from that?

In my limited experience, 2 NIC's are useful when in a multi-homed situation. This does not seem to be your case, as you don't have to route traffic to multiple providers.

----------

## bytelab

The reason I want two NICs is because I want to get two different addresses from my ISP, so that the webserver and the game server can't be reached at the same address. Put simple, the webserver and the game server should each have a unique address, although they are hosted on the same server.

----------

## FiNCH

the proper way to do this, especially if you only have 1 isp incoming..is to use 1 nic with multiple aliases just like minkspower said

----------

## minskpower

Ok, 2 NICs on a single upstream line will only get you in trouble.

Get rid of one, write aliases for only one NIC, then bind the game server to one alias, bind all other services on the other, then use the second one as a default out interface for any other traffic. You might want to check your routing table.

----------

## bytelab

Ok, this discussion really tells me what a total n00b I am...

If I understod this right, it is possible to have two IP addresses assigned to one NIC using this alias technique?

Since my ISP gives me IP addresses via dhcp (I am not able to set them manually), can I have my eth0 request two addresses, one for it self and one for its alias? How do I set this up in my network configuration? Anyone know a good tutorial I could look at?

thanks for the replies by the way!

----------

## Tjofras

hmm dosent most DHCP servers assign only one ip per MAC address?

Ive been trying todo the same thing but i fail to get the DHCP server to give me more then one IP per MAC address.

There is something called ClientID

```

man dhcpcd:

 -I <ClientID>

              Specifies the client identifier string.  dhcpcd uses the default client identifier (MAC address of the  network  inter-

              face) if it is not specified.

```

But my i cant get this to work (maybe my ISPs DHCP server dosent allow me to do so).

If you can get multiple static ips its a easy task.

if you cant get any data trough at all you may find your answer in your routingtable. (route -n to show your routeing table)

----------

## Zarhan

As others have said, you should probably use alias interfaces. However, since DHCP is troublesome when requesting multiple IPs, you may have to resort to bridging and tun/tap interfaces.

In effect - get rid of the other NIC.

emerge bridge-utils

Create TAP interfaces tap0 and tap1, each with a different MAC address (something that resembles a real MAC, 00:11:22:33:44:55 and 00:11:22:33:44:56 may work - but there may be some sanity checks).

Create bridge br0

Insert NIC eth0 and tap interfaces tap0 and tap1 to the bridge.

Request IPs for tap0 and tap1 (ie. use dhcpcd normally). For your "non-default" interface use dhcpcd option -m 10 to give it a higher metric (ie. less preference, making tap0 the "default"). 

Bind applicable servers to tap1.

----------

## minskpower

Best solution is Zarhan's, I was ignorring the fact that you get IP's via DHCP (sorry).

----------

## bytelab

okay, Zarhan's solution seems pretty nice! I've never tried the bridge-utils before but I will have a look at it during the weekend. Will a bridge still give me 2 global IP addresses that can be used to reach my server over the internet?

Thanks for all your replies people. I will get back to you with the results as soons as possible.

EDIT:

I read a little from this wiki just to get some details on the bridge-utils. Still dont understand, how do I create these TAP interfaces?

----------

## sedorox

You could do it either way.. personally.. I haven't had luck with dhcp on virtual interfaces on one nic. HOWEVER.. what you want to check... your routing table (route -n).. you should notice two default's down at the bottom.. what I think is happening is the  dhcp is assigning the address, and default route for the first nic.. then again for the second... the problem with having two default routes (at least in the same routing table.. but this touches on advanced routing.. which you don't need) is that the box doesn't know which nic to send the information.  I would suggest, since both IPs are probably in the same block, and that the default gateway's are the same, just remove the default gateway for the second nic, and leave the first there.. this way.. you will still be able to get out, and both IPs should be usuable.

----------

## Zarhan

 *sedorox wrote:*   

> . your routing table (route -n).. you should notice two default's down at the bottom.. what I think is happening is the  dhcp is assigning the address, and default route for the first nic.. then again for the second... the problem with having two default routes (at least in the same routing table.. but this touches on advanced routing..

 

  This is why there is a -m option at my suggestions  :Smile: 

  However, if you do it with two NICs, ie. remove or downgrade the "other" NIC's default gateway, the result is still "asymmetric" routing - ie. incoming packets to a server come in via eth1, but replies from the server go out from eth0. Now, technically, this *should* work since the source address *should* still be the address from eth1... (You might want to check what's happening with Ethereal or something). 

  With tap interfaces you can be certain that the addressing is correct.

  If this were a Cisco router I would do stuff like this with route-maps...but I'm not sure how that's done in Linux.

----------

## bytelab

ok, two questions...

sedorox:

 If I use two NICs and just remove the default route (I guess this could be done with the "nogateway" option in /etc/conf.d/net) for eth1, will it still be usable? I.e. can it send data to the internet without a default route? Or will all outgoing data go through eth0 (which still has a default route)?

zarhan:

 Your solution seems quite nice, but how do I set this up in Gentoo? I have emerged the bridge-utils, now what?

Also, I'm not 100% sure I've understod this bridge setup...With your solution, will my server have two usable IP addresses, each for every tap interface, that I can use just like if they were two physical NICs addressed byt my ISPs dhcp server? 

BTW, I'm really thankful for all your replies guys!

----------

## Zarhan

 *bytelab wrote:*   

> sedorox:
> 
> If I use two NICs and just remove the default route (I guess this could be done with the "nogateway" option in /etc/conf.d/net) for eth1, will it still be usable? I.e. can it send data to the internet without a default route? Or will all outgoing data go through eth0 (which still has a default route)? 

 

  In both cases, ALL packets will go out of eth0. But the source address will probably be of eth1:s.

  Like I said, check with Ethereal.

  Anyway, this SHOULD work. Are you directly connecting the NICs to some upstream providers Ethernet jack or do you have your own switch/DSL modem before going upstream? It's just that if the ISP have some sort of antispoofing in place, and you get an address for eth1 but the ISP sees packets with eth1:s address coming out of eth0 -> it may decide to drop them.

 *bytelab wrote:*   

> 
> 
> zarhan:
> 
>  Your solution seems quite nice, but how do I set this up in Gentoo? I have emerged the bridge-utils, now what?
> ...

 

  With baselayout 1.12 at least it should probably go like this:

```
config_tap0=("00:11:22:33:44:55")

config_tap1=("00:11:22:33:44:56")

bridge_br0="eth0 tap0 tap1"

config_eth0=( "null" )

config_tap0=( "dhcp" )

config_tap1=( "dhcp" )

```

  Mind you, I have never tried this out.

----------

## Zarhan

Ok, I think I found a link that might provide you with what you need:

http://linux-ip.net/html/adv-multi-internet.html

In effect, route maps. This may also work with applications that don't even allow you to bind to a specific interface, but reply in all. 

(So ignore all the previous suggestions  :Smile: )

----------

## bytelab

 *Quote:*   

>  Are you directly connecting the NICs to some upstream providers Ethernet jack or do you have your own switch/DSL modem before going upstream?

 

I have a single port ethernet jack on my wall. From this jack I have connected a 8-port standard switch (so that I can connect more than one computer/NIC and use all 5 IPs). No modem or anything needed. My server and its two NICs are then connected to this switch. Very simple setup I guess...

 *Quote:*   

> In both cases, ALL packets will go out of eth0. But the source address will probably be of eth1:s.

 

Ok, so if I would like two NICs, both able to operate on its own (being addressed via dhcp, send/recieve data etc.) I'm in to some deep water...?

I'm going to give the bridge setup a try when I get home later today.

----------

## bytelab

 *Zarhan wrote:*   

> Ok, I think I found a link that might provide you with what you need:
> 
> http://linux-ip.net/html/adv-multi-internet.html
> 
> In effect, route maps. This may also work with applications that don't even allow you to bind to a specific interface, but reply in all. 
> ...

 

checking....

I'll let you know if I have any progress.

----------

## bytelab

Hello again!

I've been playing around a little with Zarhan's bridge solution. I think I'm on the right track, but I just can't get it to work. This is what I have done:

Recompiled my kernel with support for the Universal TUN/TAP driver (2.6.15-gentoo-r1)

Emerged bridge-utils and usermode-utilities (don't know what they are good for, but I've read they are needed...)

Edit my /etc/conf.d/net like this:

```
config_tap0=("00:02:E3:23:E0:02")

config_tap1=("00:02:E3:23:E0:03")

bridge_br0="eth0 tap0 tap1"

config_eth0=( "null" )

config_tap0=( "dhcp" )

config_tap1=( "dhcp" )
```

```
cd /etc/init.d/

ln -s net.lo net.eth0 

ln -s net.lo net.tap0

ln -s net.lo net.eth1

ln -s net.lo net.br0
```

connected my network cable (duuuh...)

Now this should do the trick, right? The problem is when I try to start my tap interfaces like this: 

```
/etc/init.d/net.tap0 start
```

I only get this:

```
 * Starting tap0

 *   Creating Tun/Tap interface tap0 ...                                                                                   [ ok ]

 *   Bringing up tap0

 *     dhcp

 *       Running dhcpcd ...
```

and than nothing more happens...no IP address assigned to the tap.

At first I had problems with the system being unable to create the tun/tap interface, but I solved this by reading up on the documentation followed by the kernel. The problem now seems to be dhcp not working properly. To be on the safe side I stole the MAC addresses of the tap's from two "real" NICs I hade lying around. 

Anyone have an idea?

----------

## bytelab

still no success...

----------

