changes to /etc/network/interfaces not working?

33,792

Solution 1

Ok, if you have one nic you can add virtual interfaces on this way

auto eth0
iface eth0 inet static
   address 192.168.1.57
   netmask 255.255.255.0
   gateway 192.168.1.1
   up ip addr add 192.168.0.57/24 dev eth0 label eth0:1
   down ip addr del 192.168.0.57/24 dev eth0 label eth0:1
   up ip route add 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20
   down ip route del 192.168.0.0/24 via 192.168.0.1 dev eth0:1 metric 20

In your question eth0 is in net range 192.168.1.xxx and eth3 is also in that range, meybe is enough to have only one interface in one network range?

You can add eth0:2 on the same way like eth0:1 if you need one more virtual interface

But this will work only in two cases.

  1. your pc is connected to switch and both router is also connected on the same switch. On this way pc can reach both router

  2. you router have primary and secondary ip address on interface

Edit 1

You must edit /etc/NetworkManager/NetworkManager.conf

sudo nano /etc/NetworkManager/NetworkManager.conf

This will open the ‘NetworkManager.conf’ file in our text editor.

Now change:

managed=false

to

managed=true

After changes reload network service

sudo service networking restart

Or if this did not work, try

sudo ifdown eth0 && sudo ifup eth0

Solution 2

Using eth2 will tell the system to use another adapter but you only have one. to define virtual adapters you should use eth0:<number>.

Try this one:

auto lo
iface lo inet loopback

iface eth0:1 inet static
        address     192.168.0.57
        netmask     255.255.255.0
        gateway     192.168.0.1

dns-nameservers    8.8.8.8 8.8.4.4

iface eth0:2 inet static
        address     192.168.1.57
        netmask     255.255.255.0
        gateway     192.168.1.1

Solution 3

To add a virtual interface type the following command in your Linux Terminal
Command:
ifconfig VIRTUAL_INTERFACE_DEVICE IP_ADDRESS netmask SUBNET_MASK up
For example,
ifconfig eth0:1 192.168.1.6 netmask 255.255.255.0 up This will create a new virtual interface named eth0:1 and assigns the IP Address 192.168.1.6.

To Make this Virtual Interface Permenant Create a new file /etc/sysconfig/network-scripts/ifcfg-eth0:1 with the following contents

DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.99
NETMASK=255.255.255.0

Type service network-manager restart after editing to apply changes.

To Up and Down the Virtual Interface, use the following commands ifup eth0:1 and ifdown eth0:1

Share:
33,792

Related videos on Youtube

wolfgang
Author by

wolfgang

Updated on September 18, 2022

Comments

  • wolfgang
    wolfgang over 1 year

    This is my /etc/network/interfaces file

    I'm trying to add 2 virtual interfaces which connect to 2 different routers of 2 different ISPs

    auto lo
    iface lo inet loopback
    
    iface eth2 inet static
            address     192.168.0.57
            netmask     255.255.255.0
            gateway     192.168.0.1
    
    dns-nameservers    8.8.8.8 8.8.4.4
    
    iface eth3 inet static
            address     192.168.1.57
            netmask     255.255.255.0
            gateway     192.168.1.1
    

    I've tried all these commands and none of them work

    sudo /etc/init.d/networking restart
    sudo /etc/init.d/networking reload`
    

    And these

    sudo ifconfig eth2 down
    sudo ifconfig eth2 up
    

    I get an error :

    eth2: ERROR while getting interface flags: No such device

    I've tried inserting manged=false in /etc/NetworkManager/NetworkManager.conf

    and then restarting sudo service network-manger restart

    When I type ifconfig -a

    All I get is

    eth0      Link encap:Ethernet  HWaddr fc:aa:14:4d:11:22  
              inet addr:192.168.1.90  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::feaa:14ff:fe4d:1122/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:8027656 errors:0 dropped:2 overruns:0 frame:0
              TX packets:20898303 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:553970620 (553.9 MB)  TX bytes:1471000436 (1.4 GB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:65536  Metric:1
              RX packets:1837917 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1837917 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:240925560 (240.9 MB)  TX bytes:240925560 (240.9 MB)
    

    My Question is : How can I add interfaces eth2 & eth3?

    • 2707974
      2707974 over 8 years
      Do you inserted nic cards or you wont to make subinterface eth0:2 and eth0:3?
    • wolfgang
      wolfgang over 8 years
      @2707974 Edited question, I'm trying to add 2 virtual interfaces which connect to 2 different ISP routers
  • wolfgang
    wolfgang over 8 years
    Could you also add a command to reload these changes.
  • wolfgang
    wolfgang over 8 years
    This is what i get when i enter that in ubuntu 14.04 stop: Job failed while stopping start: Job is already running: networking I've mentioned in the question that this did'nt work, is this another way to reload the interface?
  • wolfgang
    wolfgang over 8 years
    I made the changes and ran sudo service networking restart and got the same error as above but on running sudo service network-manager restart i get this result -> oi62.tinypic.com/34zdfd0.jpg the connection eth1 is visible as ifupdown(eth1) but it does'nt show up on ifconfig -a. Any suggestions?
  • 2707974
    2707974 over 8 years
    Today is not my day. I make mistake and now correct them. Please look again at the beginning of answer in first code and correct eth1 to eth0
  • wolfgang
    wolfgang over 8 years
    This is my interfaces file pastebin.com/L22HHcJ7 I ran both the above commands including sudo ifconfig eth0 down && sudo ifconfig eth0 up and the result when typing ifconfig -a is the same as the screenshot. wonder what's missing...
  • 2707974
    2707974 over 8 years
    Do not use ifconfig use ifup and ifdown. ifconfig do not read /etc/network/interfaces
  • wolfgang
    wolfgang over 8 years
    ah, thanks for your support, but when i give sudo ifup eth0 I get RTNETLINK answers: File exists Failed to bring up eth0
  • wolfgang
    wolfgang over 8 years
    Ah, Now it works! I had to reboot the system. Still dont know why i got that RTNETLINK message, . wish i could get it to work without rebooting though, Thanks anyway!
  • wolfgang
    wolfgang over 8 years
    Hey, an update, Removing spaces before iface in the second line worked! -> this is how the file looks like > pastebin.com/qDi6mSwR. and i had to run sudo ifdown eth0 && sudo ifup eth0 after that. Could you please add it into your answer so it may help someone?
  • 2707974
    2707974 over 8 years
    I correct answer
  • fatal_error
    fatal_error over 6 years
    FYI for other readers: the second part of this answer (/etc/sysconfig) is applicable to Red Hat derivatives, but not Debian derivatives like Ubuntu.
  • DevOpsSauce
    DevOpsSauce about 3 years
    managed=true helped me. Thanks!