-1

I've created a virtual interface in Ubuntu with the following:

sudo ifconfig eth0:0 192.168.1.99 netmask 255.255.255.0 up

Now I need to be able to ping from the new virtual interface.

ping -I 192.168.1.99 www.google.co.in

I am unable to do that. I have enabled IP forwarding.

larsks
  • 43,623
  • 14
  • 121
  • 180

1 Answers1

0

The ping -I option should just work, I might be mistaken but it works out-of-the-box in the examples below, and ive not enabled forwarding. Can you provide your ifconfig and netstat -r output.

Normally the source IP would be set depending on the network interface for the appropriate route for the target address, so if eth0:0 was also an appropriate IP for the interface you end up with 1 of 2 possibilities like so;

  1. for example, if my ip address is 192.168.1.72 like so;

    # ifconfig  
    eth0      Link encap:Ethernet  HWaddr 00:04:4B:16:BA:41   
              inet addr:192.168.1.72  Bcast:192.168.1.255  Mask:255.255.255.0
    

    and I add another IP address, like your command;

    ifconfig eth0:0 192.168.1.99 netmask 255.255.255.0 up
    

    then I would end up with the following

    # ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:04:4B:16:BA:41  
              inet addr:192.168.1.72  Bcast:192.168.1.255  Mask:255.255.255.0
    
    eth0:0    Link encap:Ethernet  HWaddr 00:04:4B:16:BA:41  
              inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0
    

    so I can ping with either the default IP bound to the eth0 interface;

    ping -I 192.168.1.72 myremote.host.com
    
    echo request...  
    echo reply....  
    

    or the new one;

    ping -I 192.168.1.99 myremote.host.com
    
    echo request...  
    echo reply....  
    

    but because, 192.168.1.xx are all local addresses behind a NAT'ted connection, the remote host at myremote.host.com just sees your external IP and not 192.168.1.72:

    20:24:21.452732 IP 87.19.24.187 > 123.123.123.123: ICMP echo request, id 49711, seq 6, length 64
    20:24:21.452757 IP 123.123.123.123 > 87.19.24.187: ICMP echo reply, id 49711, seq 6, length 64
    

    where 87.19.24.187 is the public address

  2. However if I set some crazy IP address to the interface, like so;

    ifconfig eth0:2 192.192.7.99 netmask 255.255.255.0 up
    

    my remote host sees the ping, but the client never gets the reply;

    # tcpdump -nn icmp and host xxx
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
    20:25:01.165321 IP xxx > yyy: ICMP echo request, id 49730, seq 1, length 64
    20:25:01.165349 IP yyy > xxx: ICMP echo reply, id 49730, seq 1, length 64
    
sebix
  • 4,313
  • 2
  • 29
  • 47
Tom
  • 11,176
  • 5
  • 41
  • 63