Linux: Setting Static or Dynamic IP Address
Virtually no computer used today would not have an IP address of some kind assigned to it. Here’s how to assign IP address settings in various Linux OS flavors. See the following sections for commands to show the current IP settings:
Direct Configuration File Method
The various Linux OS families have different ways to set their IP address (on the command line), typically through a configuration file and a restart of a system service.
vi /etc/NetworkManager/system-connections/<IFACE_NAME>.nmconnection
systemctl restart NetworkManagervi /etc/network/interfaces
systemctl restart networkingvi /etc/network/interfaces
vi /etc/resolv.conf
/etc/init.d/networking restartvi /etc/systemd/network/10-net0.link
> [Match]
> PermanentMACAddress=<interface MAC address>
>
> [Link]
> Name=net0
>
> [Network]
> Address=<address>
> Gateway=<gateway>
> DNS=<dns1>
> DNS=<dns2>Ubuntu
In this case, like many others, even though Ubuntu is a Debian derrivative it doesn’t follow Debian’s example, and has to do it it’s own ‘special’ way:
vi /etc/netplan/<interface>_config.yaml
netplan applyNetworkManager Method
Many distributions support various network managers - command line tools to consolidate and simplify the commands to manage IP address settings. Several distributions support NetworkManager and I’ve made notes here to show how to install NetworkManager and the commands to set static IP values
dnf -y install NetworkManager
systemctl enable --now NetworkManager
nmcli connection modify <iface name> ipv4.gateway <gateway ip>
nmcli connection modify <iface name> ipv4.address <ip address>
nmcli connection modify <iface name> ipv4.dns <dns ip address>
nmcli connection up <iface name>apt-get install network-manager
systemctl enable --now NetworkManager
nmtuiapk add networkmanager
rc-service networkmanager start
rc-update add networkmanager default
adduser <your username> plugdev #you will need to relog to apply the new group membership
nmtuipacman -Syu networkmanager
systemctl --now enable NetworkManager.service
nmtui