nmcli connection addnmcli connection cloneip route addsstracepathA device can have several saved profiles; only one is active at a time.
# Create a brand-new connection profile from scratch nmcli connection add type ethernet con-name static-eth0 ifname eth0 \ ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1 # Duplicate an existing profile as a starting point for a new one nmcli connection clone eth0 eth0-backup # Rename a connection profile nmcli connection modify eth0-backup connection.id eth0-lab # Delete a connection profile entirely nmcli connection delete eth0-backup # Control whether a profile activates automatically at boot nmcli connection modify static-eth0 connection.autoconnect yes
NetworkManager stores each profile as a keyfile. Edit with nmcli or nmtui; knowing the location helps with auditing and backups.
# Connection profiles are stored here, one file per connection ls /etc/NetworkManager/system-connections/ # View a profile's raw keyfile contents (readable only by root) sudo cat /etc/NetworkManager/system-connections/static-eth0.nmconnection
nmcli connection reload, then reactivate the connection.# View the current routing table ip route show # Add a temporary static route (lost on reboot / interface restart) sudo ip route add 10.10.20.0/24 via 192.168.1.254 # Remove a route sudo ip route del 10.10.20.0/24 # Add a PERSISTENT static route to a connection profile nmcli connection modify eth0 +ipv4.routes "10.10.20.0/24 192.168.1.254" # Reactivate the connection to apply it nmcli connection up eth0
ip route changes the running system now but saves nothing. nmcli saves the change but applies it only when the connection is reactivated.# Set one or more DNS servers on a connection nmcli connection modify eth0 ipv4.dns "192.168.1.1 8.8.8.8" # Set a DNS search domain, so short names get it appended automatically nmcli connection modify eth0 ipv4.dns-search example.com # Prevent DHCP-provided DNS servers from being used, keeping only the ones set above nmcli connection modify eth0 ipv4.ignore-auto-dns yes # Apply the changes nmcli connection up eth0 # Confirm what's actually in effect right now cat /etc/resolv.conf
/etc/resolv.conf from connection profiles. Make DNS changes with nmcli.One connection can hold several IPv4 addresses, so one interface can answer on more than one address.
# Add a secondary address without replacing the primary one nmcli connection modify eth0 +ipv4.addresses 192.168.1.51/24 # Remove a specific secondary address nmcli connection modify eth0 -ipv4.addresses 192.168.1.51/24 # Apply the change nmcli connection up eth0
+ adds an item and - removes one. With neither, the value replaces the whole list.# Overall connectivity status summary nmcli general status # Full detail on one device: state, IP config, DNS, routes nmcli device show eth0 # Show listening TCP and UDP sockets, with numeric ports ss -tuln # Trace the network path to a destination, hop by hop tracepath example.com # Watch DNS resolution specifically getent hosts example.com
/etc/NetworkManager/system-connections/ip route add and adding a route with nmcli?/etc/resolv.conf unreliable on a NetworkManager system?+ and - prefixes do in nmcli connection modify?eth0?