Add a second network card in Linux

2

There are a number of places that suggest adding a couple of lines to /etc/network/interfaces, and restarting the networking daemon sudo /etc/init.d/networking restart. [1] [2]

However, this is something of a pain for a virtual machine for which I only know the desired configuration of the second nic at runtime, and may not want the changes to persist. Is there some way to only temporarily use a second nic, without having to add and then delete lines from the configuration file?

Scott

Posted 2018-04-16T17:58:34.080

Reputation: 214

1

yes it's possible to do that with the command line but if you reboot your machine all the configuration will be lost. https://help.ubuntu.com/community/NetworkConfigurationCommandLine/Automatic

– D'Arcy Nader – 2018-04-16T18:06:55.633

That is exactly the behavior I was desiring. I will accept your comment as an answer, if it were to somehow become one. – Scott – 2018-04-16T18:09:51.367

Answers

3

yes it's possible quoting from ubuntu eth0 configuration

We will use eth0 in this example, your interface can be named differently, see Finding your network interface.

If you have disabled the either wicd or the network manager you probably don't have a network connection anymore. Connect via a regular UTP cable to your router, and assuming you have DHCP enabled do the following:

sudo ip link set dev eth0 down
sudo dhclient eth0

This will bring your eth0 up by using DHCP. Your network is now configured (for the time being).

If you don't have DHCP enabled configure your network by issueing the commands below, the gateway address is the IP address of your router. And your IP should be in the same range as the router is.

sudo ip addr add 192.168.1.14/24 dev eth0
sudo ip link set dev eth0 up
sudo ip route add default via 192.168.1.1

These commands configure your interface but these changes will not survive a reboot, since the information is not stored anyhwere.

D'Arcy Nader

Posted 2018-04-16T17:58:34.080

Reputation: 145