6

I'm using CentOS 7 and I setup a new connection with nmcli. I set the gateway but it doesn't seem it took. When I check the connection with

nmcli con show conn-name

the gateway is listed as: gw = 0.0.0.0

I can't find how you add/modify the gateway with nmcli.

Nothing is listed in nmcli connection modify.

Can you edit/add the gateway address with nmcli after the connection has been added?

As a work around, I edited /etc/sysconfig/network-scripts/ifcfg-connname and added GATEWAY0=addr

I'm assuming you can't update the gateway address from nmcli?

3

For older implementations (such as CentOS 7) you can use:

nmcli con modify <name> ipv4.addresses "<ip addr and mask> <gateway>"

to add a gateway to the connection. For example:

# nmcli con modify eth0 ipv4.addresses "192.168.1.10/24 192.168.1.1"

then confirm with:

# nmcli con show eth0 | grep ipv4\.addresses
ipv4.addresses         { ip = 192.168.1.10/24, gw = 192.168.1.1 }

Later implementations have ipv4.gateway which you can modify:

nmcli con modify <name> ipv4.gateway <gateway>

For example:

# nmcli con modify eth0 ipv4.gateway 192.168.1.1
1

To create a connection with the name ethernet-eth0, the IPv4 address 192.168.1.10/24 and the default gateway 192.168.1.1, type:

nmcli con add con-name net-eth0 ifname eth0 type ethernet ip4 192.168.1.10/24 gw4 192.168.1.1

If you don’t specify con-name net-eth0, the connection is called ethernet-eth0.

If you don’t specify the ip4 192.168.1.10/24 gw4 192.168.1.1 part, you end up with a connection automatically configured through DHCP.

nmcli con up net-eth0 is not necessary when initially configuring a connection.

  • Just to make sure I understand, after the connection is created with nmcli, and if you forgot to define the gateway when creating it, you cannot add the gateway using the nmcli command. Correct? To add it you would have to modify the connection in /sysconfig/network-scripts/ ... etc – Oscalation Feb 25 '16 at 15:43
1
  1. If you should modify/add gateway on interface eth0, you can using command:
    nmcli con modify eth0 ipv4.gateway "192.168.1.1"
    nmcli con reload eth0
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.