Linux: Set a static/fixed IP with Network Manager Cli

Hi,

most of the Linux Distributions uses the NetworkManager to configure network connections.

Sometimes it is necessary to set a static IP address, i.e. if no DHCP Server is available on the network or you want to setup a peer to peer connection between the computers.

List connections

root@debdev ~ # nmcli con
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  fac58792-304a-b3dd-88ad-b689ba1495b2  ethernet  eth0

And set IP Address, DNS search domain, DNS server and default gateway

root@debdev ~ # nmcli con mod "Wired connection 1" \
  ipv4.addresses "10.200.2.200/24" \
  ipv4.gateway "10.200.2.1" \
  ipv4.dns "10.200.2.2,10.200.2.3" \
  ipv4.dns-search "myDomain.org" \
  ipv4.method "manual"

Its also possible to edit the config file. The connection config are placed in /etc/NetworkManager/system-connections

root@debdev ~ # cd /etc/NetworkManager/system-connections
root@debdev ~ # ls -l 
-rw------- 1 root root 316 Jun  4 22:56 'Wired connection 1'

Edit the IPv4 section. This also describes how to set a static route

[ipv4]
address1=10.200.2.200/24/24,10.200.2.1
dns=10.200.2.2;10.200.2.3;
dns-search=myDomain.org
method=manual
route1=224.0.23.12/32

Michael

Advertisment to support michlstechblog.info

One thought on “Linux: Set a static/fixed IP with Network Manager Cli”

Leave a Reply to Sachin Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.