operating-systems linux

Configuration

Change Status

To change the status of a link, the ip link set command can be used:

sudo ip link set <interface> <up|down|...>

Example:

sudo ip link set ens18 up

IP Address

To remove all ip addresses of an interface, the ip addr flush command can be used:

sudo ip addr flush dev <interface>

Example:

sudo ip addr flush dev ens18

where ens18 is the name of the network interface.

An ip address can be added to an interface using the ip addr add command:

sudo ip addr add <ip-address>/<prefix-length> dev <interface>

Example:

sudo ip addr add 192.168.10.1/24 dev ens18

where ens18 is the name of the network interface and 192.168.10.1 is the ip address and 24 is the prefix length, which corresponds to a network mask of 255.255.255.0.

Default Gateway

The default gateway of an interface can be configured using the ip route command:

sudo ip route flush default
sudo ip route add default via <gateway-ip> dev <interface>

Example:

sudo ip route flush default
sudo ip route add default via 192.168.10.1 dev ens18

where ens18 is the name of the network interface and 192.168.10.1 is the IP address of the default gateway.

DNS Nameserver

Change DNS nameservers

The DNS nameservers can be configured in /etc/resolv.conf. For example, to use Cloudflare’s nameservers:

options edns0

nameserver 1.1.1.1
nameserver 1.0.0.1