# MultiHome / IP Alias

## atl_linux

I am trying to setup a machine to connect to two seperate networks with a single ethernet card.  I thought this was called multihome/IP aliasing but searches in the various HOWTO's and forums didn't return the results I am looking for.

What I am trying to setup is a computer that has both a DHCP address (internal network) and a Static IP (external network).  I would like for both of these to run over a single network card.

Right now I can ifup/ifdown the card and change the network settings so that it can communicate with machines on the respective networks.  I would just like to be able to do both at the same time if its possible.

The other solution would be to buy a small hub/ second ethernet card and place the hub in between my linux box and my ethernet wall outlet.

From what I gleaned off various websites it should be something like

this.

eth0:0 DCHP

eth0:1 Static IP

They are 2 distince networks and should each have their own route tables.

Is this possible?  Does anyone have some good links to review to help with this setup?  

thanks,

Chris

----------

## devon

Have you tried it? I imagine your /etc/conf.d/net file would look like

```
iface_eth0="dhcp"

alias_eth0="192.168.1.150"
```

Here is what I got using that:

```
/etc/init.d/net.eth0 restart

 * Bringing eth0 down...

 *   Waiting for dhcpcd to shutdown.....done                                                                     [ ok ]

 * Bringing eth0 up...                                                                                           [ ok ]

 *   Adding aliases...

 *     eth0:0...                                                                                                 [ ok ]
```

ifconfig

```
# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:20:ED:3F:89:95

          inet addr:real.ip.of.provider  Bcast:255.255.255.255  Mask:255.255.252.0

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:570278418 (543.8 Mb)  TX bytes:122342079 (116.6 Mb)

          Interrupt:18 Base address:0xbf00

eth0:0    Link encap:Ethernet  HWaddr 00:20:ED:3F:89:95

          inet addr:192.168.1.150  Bcast:192.168.1.255  Mask:255.255.255.0

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:18 Base address:0xbf00

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:12 errors:0 dropped:0 overruns:0 frame:0

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

          collisions:0 txqueuelen:0

          RX bytes:600 (600.0 b)  TX bytes:600 (600.0 b)

```

route -n output

```
# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

12.220.72.0     0.0.0.0         255.255.252.0   U     0      0        0 eth0

0.0.0.0         12.220.72.1     0.0.0.0         UG    0      0        0 eth0
```

That what you looking for? I left the "gateway" option in /etc/conf.d/net #'ed, but you may have to set it.

----------

## addi

i did exactly this behaviour, but i am unable to ping anything on the internal network (static ip - 192.168.0.10 is the alias).  the eth0 normal ip is a dhcp allocated address.

something to do with the gateway/routing tables?  I am definitely confused.   Any takers?

----------

## jsleeper

I've never before set up a linux box as a router, just cisco equipment (part of my job).  In my experiences, it's generally a bad idea to set up a network this way.  Network cards are cheap these days, i would suggest getting another one and have one interface for each network.  If you absolutely must use one card, i'd suggest using 802.1q vlans.  I've seen that option in the kernel config, but have never played with it.  You have to have a switch that can be configured for different vlan encapsulations in order for it to work though.

It seems possible that you can get your setup working without additional hardware, but in the long run I think you'd be much happier spending a few dollars on another network card and setting it up the proper way.

joe

----------

## devon

 *addi wrote:*   

> i did exactly this behaviour, but i am unable to ping anything on the internal network (static ip - 192.168.0.10 is the alias).  the eth0 normal ip is a dhcp allocated address.
> 
> something to do with the gateway/routing tables?  I am definitely confused.   Any takers?

 

What does "/sbin/route -n" show you?

----------

## splooge

Works fine for me this way.

To the cisco guy: think: subinterface.  it's not a bad thing.

```

eth0      Link encap:Ethernet  HWaddr 00:50:DA:B9:73:DA

          inet addr:66.74.153.7  Bcast:255.255.255.255  Mask:255.255.240.0

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:1945561 (1.8 Mb)  TX bytes:393776 (384.5 Kb)

          Interrupt:12 Base address:0xc000

eth0:0    Link encap:Ethernet  HWaddr 00:50:DA:B9:73:DA

          inet addr:10.1.1.1  Bcast:10.255.255.255  Mask:255.0.0.0

          UP BROADCAST NOTRAILERS RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:1945561 (1.8 Mb)  TX bytes:394122 (384.8 Kb)

          Interrupt:12 Base address:0xc000

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:0 errors:0 dropped:0 overruns:0 frame:0

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

          collisions:0 txqueuelen:0

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

```

what i use to get me out on to the net:

```

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

```

And my eth0 is dhcp:

```

694 ?        S      0:00 /sbin/dhcpcd eth0

```

route -n:

```

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

66.74.144.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0

10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 eth0

127.0.0.0       127.0.0.1       255.0.0.0       UG    0      0        0 lo

0.0.0.0         66.74.144.1     0.0.0.0         UG    0      0        0 eth0

```

HTH

----------

## TenPin

I've never tried this but it certainly sounds useful if you wanted to setup a XBOX as a cheap internet gateway.

They way I figure it is that there is no difference between having 2 ethernet cards and having 1 card with multiple addresses except for performance issues once the load gets high. Anyone who knows care to comment ?

Does anyone know how switches work? The way I see it is that a switch has discover which IP addresses are associated with each port/MAC#. If you had one NIC with 256 ips what does the switch have to do to keep track of what packet goes where. I know it doesn't broadcast all the data, hubs do that but do switches broadcast initially to find the target? Would that mean that switches have some basic knowledge of the IP level? I really haven't a clue but I'd be interested to know.

----------

## TenPin

http://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.iproute2.arp.html

Answers my question.[/url]

----------

## jsleeper

The reason that I don't like to set up subinterfaces this way is that you are not physically creating seperate subnets, just logically.  If the outside world is plugged into the same hub/switch then it's very easy for someone to come in from the outside to sniff traffic/scan that subnet.  This is especially the case if it is all hooked up to a hub.  All traffic destined to the gateway is also sent to the outside world.  Switches aren't entirely safe from sniffing either - ever heard of a program called ettercap?  It's in portage.  So any effort on configuring the router for security, such is getting iptables to work, is essentially wasted.

joe

----------

## binkley

 *devon wrote:*   

> Have you tried it? I imagine your /etc/conf.d/net file would look like
> 
> ```
> iface_eth0="dhcp"
> 
> ...

 

I would like to do the same except that I don't know the aliased IP.  I have a host connected to a router-hub that does the actual DHCP.  I have eth0 as static to one of the IPs offered by the router-hub for the home network, and would like to alias eth0:1 to the IP which the router-hub obtains from my ISP via DHCP.  Right now I'm hand-crafting it each time upon boot by reading the IP from a web page served up by the router-hub.

I wanted to avoid editing /etc/init.d/net.eth0 but I don't see any kind of /sbin/ifup script or the like and /etc/conf.d/net.eth0 just takes hard-coded values AFAICT.  What's my best bet?

Thanks,

--binkley

----------

