Ubuntu: changes to /etc/network/interfaces not working?



Question:

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?


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

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


Solution:3

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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »