Let's see how to configure network interfaces on Linux. When configuring network interfaces using ip 1
or ifconfig commands, you must execute the commands as root, otherwise you get an “Operation not 2
permitted” error. 3
To make it easier I’m temporarily becoming root in the terminal by running 4
sudo su 5
Do not run the following commands on a remote system to which are connected using ssh, since 6
you are going to disable and enable interfaces, change IP addresses and so on 7
and your ssh connection will drop around. Run the commands on a Linux machine 8
to which you have local access. 9
Let's see how we can set interfaces up and down. 10
So ifconfig, the name of the interface enp0s3 down. 11
The interface is down and it's not displayed by the ifconfig, command. Use the -a option 12
to display it. 13
And we notice that’s not running, so it’s down. And I'll activate the interface. 14
ifconfig, the name of the interface and up. 15
We see the interface is running. 16
Let's do the same using the IP command: ip link, set the name of the interface, enp0s3 down 17
and ip link show dev and the name. 18
And the interface is in the down state; I'm activating the interface. 19
I'll use up instead of down. 20
And I'm checking it; now 21
the interface is up. 22
Let's go ahead and configure an IP address on the interface; note that the configurations set with 23
the ip and ifconfig commands are not persistent. 24
After a system restart, all changes will be lost; for permanent settings 25
you need to edit a distro specific configuration file. 26
For example, on Ubuntu, you have to use a net plan for a static configuration of the network. 27
Will have an entire lecture on this later in the course. 28
ifconfig, the interface name, the ip address 29
and the network mask, using the slash notation; and optionally I can add the up keyword. 30
Let's check it! 31
And we see the new IP address! And the now with the IP command, the first step is to remove the existing 32
IP address from the interface. 33
So ip address 34
del the existing IP address and its mask 35
dev and the interface name and the next step is to add the needed IP address. 36
p address you want to sit on the interface, for example, 37
222 at the end. 38
And it was changed! Let's the routing table, including the default gateway. For that, as we've already 39
discussed in the last lecture, we ran route-n 40
The capital Gin the Flegs column indicates that the line is displaying that default gateway. 41
This is the default gateway! 42
And the same with the ip command: ip route show. 43
Let's see how to change the 44
default gateway 45
If there is already a default gateway configured, then we have first to remove it, so route del 46
default gw 47
and the ip address 48
And to add a new one quickly I'm running out at default gw and this IP address. 49
And with the ip command, if there is already a default gateway rconfigured, I'm removing it. 50
ip route del default and Im adding a new one ip route del default via and the IP address of the new 51
default gateway 52
Let's check it; perfect! 53
And finally, let's see how to change the MAC address of an interface: the first step is to disable the 54
interface. 55
So ifconfig enp0s3 the name of the interface down. 56
The interface was disabled and ifconfig, the name of the interface, hw ether and the new MAC address 57
I write a random MAC address 58
And ifconfig enp0s3 up 59
And we see the new MAC address configured on that interface. 60
And the syntax for adding the MAC address using the ip command: ip link set dev the name of 61
the interface address 62
and the MAC address; I'll copy and paste this value and change the last digit 63
and ip link show dev enp0s3 The MAC address was changed; note to the configuration is valid 64
only up until a new restart. 65
As time passes, IP will replace 66
ifconfig, even though it's still here to stay for a while. 67
In the next lecture, I'll show you how to set up a static network configuration on Ubuntu.