4

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?

  • Do you inserted nic cards or you wont to make subinterface eth0:2 and eth0:3? – 2707974 Sep 22 '15 at 9:58
  • @2707974 Edited question, I'm trying to add 2 virtual interfaces which connect to 2 different ISP routers – wolfgang Sep 22 '15 at 10:02
5

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

  • Could you also add a command to reload these changes. – wolfgang Sep 22 '15 at 10:38
  • 1
    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 Sep 22 '15 at 11:29
  • 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? – wolfgang Sep 22 '15 at 12:25
  • 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 – 2707974 Sep 22 '15 at 12:29
  • 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... – wolfgang Sep 22 '15 at 14:06
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
1

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

  • FYI for other readers: the second part of this answer (/etc/sysconfig) is applicable to Red Hat derivatives, but not Debian derivatives like Ubuntu. – fatal_error Feb 8 '18 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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