Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to have two IPs sharing the same interface and it's just working fine by creating a virtual interface using the following command (eth0 is my original interface):

ifconfig eth0:0 <someip> netmask <somenetmask>

It works fine and I can see it using ifconfig until I restart the system. So, I did create ifcfg-eth0:0 in /etc/sysconfig/network-scripts/ with this content:

DEVICE=eth0:0
IPADDR=<some ip>
NETMASK=<some netmask>
ONBOOT=yes

However, when I put this virtual interface up, it overwrites the original interface and when I put original interface up, it overwrites the virtual interface. I just can't use both at the same time when I'm using the permanent way.

P.S.: I use the following commands to put interface up:

# To make up    
ifup eth0 
ifup eth0:0

I'm using cent-OS

share|improve this question
add comment

2 Answers 2

I can't replicate that problem with Centos. Have you tried eth0:1 instead of eth0:0? Also, I noticed that ifup eth0 brings up all virtual interfaces, so you don't need to ifup eth0:1.

Tested with Centos 6.4.

share|improve this answer
    
i'm using it under virtual box i think the problem is somehow related to that –  sia Aug 27 '13 at 15:13
    
I'm also running it in virtual box –  Hugo Vieira Aug 27 '13 at 17:31
    
What happens, if you rename ifcfg-eth0:0 to ifcfg-myname? Will ifup eth0 sill bring up eth0:0? –  Nils Sep 30 '13 at 10:24
add comment

These are the steps that I generally follow to create a virtual interface (aka. network alias) on Red hat based distros:

  1. create network config file

    $ cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
    TYPE=Ethernet
    DEVICE=eth0:0
    IPADDR=192.168.1.2
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    BROADCAST=192.168.1.255
    ONBOOT=yes
    NAME=eth0:0
    BOOTPROTO=none
    USERCTL=no
    IPV6INIT=no
    ONPARENT=yes
    PEERDNS=yes
    
  2. remove GATEWAY= lines from base ifcfg file:

    $ cat /etc/sysconfig/network-scripts/ifcfg-eth0
    TYPE=Ethernet
    DEVICE=eth0
    IPADDR=192.168.1.1
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    BROADCAST=192.168.1.255
    ONBOOT=yes
    NAME=eth0
    BOOTPROTO=none
    USERCTL=no
    IPV6INIT=no
    ONPARENT=yes
    PEERDNS=yes
    
  3. add GATEWAY= line to network config file:

    $ cat /etc/sysconfig/network
    HOSTNAME=grinchy
    NETWORKING=yes
    GATEWAY=192.168.1.254
    
  4. start networking

    # start just eth0:0
    $ ifup eth0:0
    
    # all networking
    $ /etc/init.d/networking restart
    

References

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.