You can use ip a
to list out devices or use ip -br a
to give an easier to read output, examples below:
user@host:~$ ip a
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 noprefixroute
valid_lft forever preferred_lft forever
2: enp31s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 70:85:c2:b4:63:4f brd ff:ff:ff:ff:ff:ff
inet 192.168.1.115/24 brd 192.168.1.255 scope global dynamic noprefixroute enp31s0
valid_lft 50588sec preferred_lft 50588sec
inet6 2a00:23c7:5199:5d01:ad6a:a018:6659:409a/64 scope global dynamic noprefixroute
valid_lft 298sec preferred_lft 118sec
inet6 fe80::a32d:3ca4:8527:b7f4/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:93:5f:05 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:03:de:e9 brd ff:ff:ff:ff:ff:ff
inet 192.168.69.1/24 brd 192.168.69.255 scope global virbr1
valid_lft forever preferred_lft forever
or
user@host:~$ ip -br a
lo UNKNOWN 127.0.0.1/8 ::1/128
enp31s0 UP 192.168.1.115/24 2a00:23c7:5199:5d01:ad6a:a018:6659:409a/64 fe80::a32d:3ca4:8527:b7f4/64
virbr0 DOWN 192.168.122.1/24
virbr1 DOWN 192.168.69.1/24
This is fine if you only have one adapter in your system. If you have multiple adatpers then it can be harder to understand which port has what name. In order to understand how Linux has enumerated the ports, you can use the lshw
command like this:
user@host:~$ sudo lshw -class network -short
[sudo] password for user:
H/W path Device Class Description
=========================================================
/0/100/1c.2/0 enp2s0 network RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
/0/100/1c.4/0 enp5s0 network NetXtreme BCM5722 Gigabit Ethernet PCI Express
/2 br0 network Ethernet interface
/3 vnet4 network Ethernet interface
There are at least two ways to achieve this in the terminal in Linux. One is a temporary measure and will not survive a reboot and the other is more permanent.
Verified on Debian and RedHat
Give the interface an IP address (in either CIDR or IP/Subnet formats)
sudo ip a add 10.10.10.43/24 dev [DEVICE]
Add default gateway
sudo ip route add default via 10.10.10.254
Using your favourite text editor, open /etc/network/interfaces
You should find a section commented as being for "The primary network interface".
Under here you can specify static settings e.g.
auto enp0s3
iface enp0s3 inet static
address 192.0.2.7/24
gateway 192.0.2.254
Save this file. Once saved, restart the networking service:
sudo systemctl restart networking.service
RedHat recommends that one of two tools are employed:
nmcli
, a command line interfacenmtui
, a text based user interfacenmcli connection add con-name enp1s0 ifname ens3 type ethernet
nmcli connection modify ens3 ipv4.method manual ipv4.addresses 192.168.122.67/24 ipv4.gateway 192.168.122.1 ipv4.dns 192.168.122.1 ipv4.dns-search home.lab
nmtui
As as setting the static IP, open /etc/network/interfaces
in your favourite text editor.
Specify the following settings
auto enp0s3
iface enp0s3 inet dhcp
Save this file. Once saved, restart the networking service:
sudo systemctl restart networking.service
RedHat recommends that one of two tools are employed:
nmcli
, a command line interfacenmtui
, a text based user interfacenmcli connection add con-name enp1s0 ifname ens3 type ethernet
nmcli device
.ens3
is both down and does not have a connection profile associated with it.nmcli connection modify enp1s0 connection.interface-name ens3
ping google.com
nmcli -g ip4 connection show enp1s0
to show the current connection status:ip a
command (add option -c
to add colour and make it easier to read).nmtui
See here
For Red Hat Enterprise Linux based systems (or possibly those utilising NetworkManager), the network configuration can be found in one of two places.
Version | Location |
---|---|
8 and below | /etc/sysconfig/Network-Scripts/ |
9 and up | /etc/NetworkManager/system-connections |
Using NetworkManager, we can also use nmcli
to gather information about the various devices and connection profiles.
Command | Explanation |
---|---|
nmcli device |
Lists all devices and their status |
nmcli connection |
Lists all connection profiles and their status |
nmcli device show [DEVICE] |
Lists out all the settings for given [DEVICE] |