ifconfig: see and make changes to network interfaces

Ifconfig allows us to make changes to our connection to the network through Linux. Today, we are going to show you how to list network interfaces on your computer and make changes to them.

Networking

At this point, you will need to have a basic understanding of networking concepts such as IP subnets and addresses. From here, we are going to execute this command to bring up all available interfaces:

sudo ifconfig
ifconfig

There are 2 network interfaces listed. Depending on how many are physically available on your computer, more will appear pre-configured. The lo interface refers to the local loopback interface within the Linux system. Traffic between software on the local system goes through here.

Also, not all interface naming schemes are the same, as they’re dependent on the manufacturer. You may find one adapter with the name eth0 or another with ens33(as pictured above).

Now we are going to change the address of our network interface. To do so, type:

sudo ifconfig ens33 192.168.1.110 netmask 255.255.255.0 broadcast 192.168.1.255

You will want to substitute the ens33 with the name of your active network interface. The 192.168.1.110 will be the new IP address identified on the network. Netmask should correlate to the /24 subnet that we are currently using which translates to 255.255.255.0. The broadcast address should also be 192.168.1.255.

Note: If your network uses a different subnet/addresses such as 192.168.2.1 or 192.168.2.66, then configure your network interface accordingly.

Run ifconfig again to see your interfaces. They have been changed according to the command that was executed earlier.

Routing

Try to ping 8.8.8.8 to check for connectivity:

sudo ping 8.8.8.8

There may not be any internet connectivity. That’s because the route to your network has been wiped from your Linux system. They will need to be added again, but to reflect the changes made to your network interface. In most cases it is the same as before.

Run the following commands:

sudo ip route add 192.168.1.0/24 dev ens33 && sudo ip route add default via 192.168.1.1 dev ens33

We are now using the ip program to add new routes to the network. First, we need to tell Linux to route all traffic to our LAN via 192.168.1.0/24. Next, we want all traffic(including internet) to be routed through our router at 192.168.1.1. Again, if your addresses are different then adjust accordingly.

Ping 8.8.8.8 once more. It should now be working.

Do note that the changes applied through ifconfig are temporary and will be overwritten by either running ifconfig ens33 up && ifconfig ens33 down or on next reboot. You will need to make permanent changes through your Linux distribution’s network configuration file.