fbpx

How to configure network interfaces on Linux?

· >

In Linux, configuring IP addresses can be done through the command line, which provides a more flexible and powerful way to manage network settings compared to graphical interfaces. In this blog post, we will discuss the basics of configuring IP addresses on Linux using the command line.

The first step in configuring IP addresses on Linux is to identify the network interface that you want to configure. This can be done using the “ip addr show” command, which will display a list of all network interfaces and their current IP addresses and status. below is a sample output for “ip addr show” command.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::211:22ff:fe33:4455/64 scope link 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:22:33:44:55:66 brd ff:ff:ff:ff:ff:ff

Once you have identified the interface you want to configure, you can use the “ip addr add” command to assign a new IP address to it. The syntax for this command is “ip addr add [IP address]/[netmask] dev [interface]”, where IP address is the new IP address you want to assign, netmask is the subnet mask, and interface is the name of the network interface. For example, if you want to assign the IP address 192.168.1.100 with a netmask of 255.255.255.0 to the eth0 interface, the command would be “ip addr add 192.168.1.100/24 dev eth0”.

Examples for “ip addr add” command.

# To assign the IP address 192.168.1.100 with a netmask of 255.255.255.0 to the eth0 interface
ip addr add 192.168.1.100/24 dev eth0

# To assign the IP address 10.0.0.100 with a netmask of 255.255.255.0 to the wlan0 interface
ip addr add 10.0.0.100/24 dev wlan0

# To assign the IP address 172.16.1.100 with a netmask of 255.255.255.0 and a broadcast address of 172.16.1.255 to the eth1 interface
ip addr add 172.16.1.100/24 brd 172.16.1.255 dev eth1

In addition to the “ip addr add” command, you can also use the “ip addr del” command to remove an IP address from an interface, or the “ip addr change” command to modify the IP address of an interface.

# To remove the IP address 192.168.1.100 from the eth0 interface
ip addr del 192.168.1.100/24 dev eth0

# To remove the IP address 10.0.0.100 from the wlan0 interface
ip addr del 10.0.0.100/24 dev wlan0

# To remove the IP address 172.16.1.100 from the eth1 interface
ip addr del 172.16.1.100/24 dev eth1

Another important aspect of IP configuration is setting the default gateway, which is the IP address of the router on your network. The default gateway can be set using the “ip route add default via [gateway IP]” command, where gateway IP is the IP address of the router.

To verify the IP configuration on Linux, you can use the “ip addr show” command again to display the current IP addresses and status of all network interfaces.

In addition to these basic commands, there are also more advanced options for configuring IP addresses on Linux, such as using DHCP to automatically assign IP addresses, or creating virtual interfaces for multiple IP addresses on a single physical interface.

In conclusion, configuring IP addresses on Linux using the command line is a powerful and flexible way to manage network settings. With the right commands and syntax, you can easily assign, remove, and modify IP addresses, and set the default gateway on your Linux system.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments