# second ip on eth0 not working [solved]

## m@o

hello everyone!

i have a problem with a second IP on the eth0 interface.

i tried to define an alias via (1) 

```
ifconfig eth0:1
```

 as well as (2) defining the ip via conf.d/net 

```
modules=( "iproute2" )

config_eth0=(    "XX.XXX.XXX.202 netmask 255.255.255.192 brd XX.XXX.XXX.255"

      "XX.XXX.XXX.221 netmask 255.255.255.192 brd XX.XXX.XXX.255" 

)

```

(1) gives:

```
# ifconfig 

eth0      Link encap:Ethernet  HWaddr 00:24:21:29:f3:54  

          inet addr:XX.XXX.XXX.202  Bcast:XX.XXX.XXX.255  Mask:255.255.255.192

          inet6 addr: fe80::224:21ff:fe29:f354/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:786283679 (749.8 MiB)  TX bytes:33243826 (31.7 MiB)

          Interrupt:29 Base address:0x4000 

eth0:1    Link encap:Ethernet  HWaddr 00:24:21:29:f3:54  

          inet addr:XX.XXX.XXX.221  Bcast:XX.XXX.XXX.255  Mask:255.255.255.192

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:29 Base address:0x4000 

```

(2) shows:

```
# ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 

    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo

    inet6 ::1/128 scope host 

       valid_lft forever preferred_lft forever

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000

    link/ether 00:24:21:29:f3:54 brd ff:ff:ff:ff:ff:ff

    inet XX.XXX.XXX.202/26 brd XX.XXX.XXX.255 scope global eth0

    inet XX.XXX.XXX.221/26 brd XX.XXX.XXX.255 scope global secondary eth0

    inet6 fe80::224:21ff:fe29:f354/64 scope link 

       valid_lft forever preferred_lft forever

```

i don't think it would make any difference which way i activate the IP.

both ways do NOT work....

i tried to ping from my first IP with success:

```
# ping -I XX.XXX.XXX.202 XX.XXX.XXX.221

PING XX.XXX.XXX.221 (XX.XXX.XXX.221) from XX.XXX.XXX.202 : 56(84) bytes of data.

64 bytes from XX.XXX.XXX.221: icmp_seq=1 ttl=64 time=0.014 ms

64 bytes from XX.XXX.XXX.221: icmp_seq=2 ttl=64 time=0.006 ms

--- XX.XXX.XXX.221 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 999ms

rtt min/avg/max/mdev = 0.006/0.010/0.014/0.004 ms

```

pinging from 221 to 202 works as well.

pinging from external hosts to 202 works.

pinging from external hosts to 221 does NOT work.

and pinging from 221 to external hosts does NOT work either.

```
# route -n 

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

XX.XXX.XXX.192   0.0.0.0         255.255.255.192 U     0      0        0 eth0

127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

0.0.0.0         XX.XXX.XXX.193   0.0.0.0         UG    0      0        0 eth0

```

the netmask and gateway are the same for both IPs. and the mac addr has to be the same for both.

i have no clue what i could have done wrong.

what may be the problem here?

any hint is apreciated.

regards m@oLast edited by m@o on Thu Jul 23, 2009 12:21 pm; edited 2 times in total

----------

## ianw1974

Easiest way:

```
ip addr add dev eth0 x.x.x.x/x
```

where x.x.x.x is the IP address and /x is the subnet mask.

----------

## bbgermany

 *ianw1974 wrote:*   

> Easiest way:
> 
> ```
> ip addr add dev eth0 x.x.x.x/x
> ```
> ...

 

If you use iproute2 as module in your /etc/conf.d/net it will do this command for you.

@ m@o: do you have any firewall rules running on the box?

bb

----------

## m@o

 *ianw1974 wrote:*   

> Easiest way:
> 
> ```
> ip addr add dev eth0 x.x.x.x/x
> ```
> ...

 

yeah well that's the same, as bbgermany said, if i add it in conf.d/net or type it per ip command.

does not work.  :Sad: 

 *bbgermany wrote:*   

> 
> 
> @ m@o: do you have any firewall rules running on the box?
> 
> 

 

no. no FW up yet. that's the strange thing! could i have overlooked something in the kernel?

m@o

----------

## bbgermany

Is the machine where you start the ping, within the same subnet? Since you use subnetting for both, ips you should make sure, that the host can reach the other subnet. Check for ipforwarding as well.

bb

----------

## m@o

 *bbgermany wrote:*   

> Is the machine where you start the ping, within the same subnet? Since you use subnetting for both, ips you should make sure, that the host can reach the other subnet. Check for ipforwarding as well.
> 
> 

 

are both on the same subnet. so ipforwarding should not be the problem...

edit: tried it:

```
# echo "1" > /proc/sys/net/ipv4/ip_forward

# ping -I xxx.xxx.xxx.202 google.com

PING google.com (74.125.127.100) from xxx.xxx.xxx.202 : 56(84) bytes of data.

64 bytes from pz-in-f100.google.com (74.125.127.100): icmp_seq=1 ttl=48 time=171 ms

64 bytes from pz-in-f100.google.com (74.125.127.100): icmp_seq=2 ttl=48 time=170 ms

--- google.com ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1005ms

rtt min/avg/max/mdev = 170.970/171.300/171.631/0.529 ms

# ping -I xxx.xxx.xxx.221 google.com

PING google.com (74.125.45.100) from xxx.xxx.xxx.221 : 56(84) bytes of data.

--- google.com ping statistics ---

3 packets transmitted, 0 received, 100% packet loss, time 1999ms

```

ping works from main eth0 ip but not from the secondary...

----------

## m@o

routing was f*cked up.

it seems my hosting provider needs ARP enabled!

```
# echo "1" > /proc/sys/net/ipv4/conf/eth0/arp_announce

# echo "1" > /proc/sys/net/ipv4/conf/eth0/arp_accept

# echo "1" > /proc/sys/net/ipv4/conf/all/arp_announce

# echo "1" > /proc/sys/net/ipv4/conf/all/arp_accept
```

thx for your help

----------

