Configure static address and route / GW with network-config-manager

Configure static address and route / GW with network-config-manager

network-config-manager is the Photon OS network configuration tool in all Photon OS 4 versions onwards to configure systemd-networkd. network-config-manager is based on ctl and yaml based configuration system that makes the configuration process way much simple.

In this tutorial, you will learn how to configure staic IP address and routes/ Gateway in Photon OS using network-config-manager.

Static Address and GW

nmctl provides set-static command to configure static address and routes/gateway .

? nmctl set-static dev [DEVICE] address|a|addr [ADDRESS]     gw|gateway|g [GATEWAY ADDRESS] dns [SERVER1,SERVER2...] keep [BOOLEAN] Configures static configuration of the device        

By default set-static creates a new .network file. To keep the previous configuration use "keep yes"

Example:

? nmctl set-static dev eth0 a 192.168.10.51/24 gw 192.168.10.1        

Let's look at the config file

? nmctl show-config dev eth0          
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Address]
Address=192.168.10.51/24

[Route]
Gateway=192.168.10.1        

With set-static multiple address and gateways can be configured at once.

? nmctl set-static dev eth0 a 192.168.10.51/24 a 192.168.10.52/24 a FE80::10 gw 192.168.10.1 gw FE80::1

? nmctl show-config eth0
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Address]
Address=192.168.10.51/24

[Address]
Address=192.168.10.52/24

[Address]
Address=FE80::10

[Route]
Gateway=192.168.10.1

[Route]
Gateway=FE80::1        

  • set-static: set address gateway and static DNS

? nmctl set-static dev eth0 a 192.168.1.12/24 gw 192.168.1.1 dns 192.168.1.2,192.168.1.1

? nmctl show-config eth0
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Network]
DNS=192.168.1.2 192.168.1.1

[Address]
Address=192.168.1.12/24

[Route]
Gateway=192.168.1.1        

nmctl also provides to set IPv4 and IPv6 Gateway with set-gw-family

set-gw-family dev [DEVICE] gw4 [IPv4 GATEWAY ADDRESS] gw6 [IPv6 GATEWAY ADDRESS] Configures device default IPv4/IPv6 Gateway.        

Example:

? nmctl set-gw-family dev eth0 gw4 192.168.10.1 gw6 FE80::1
? nmctl show-config eth0
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Address]
Address=192.168.10.51/24

[Address]
Address=192.168.10.52/24

[Address]
Address=FE80::10

[Route]
Gateway=192.168.10.1

[Route]
Gateway=fe80::1        

Remove GW from device

With remove-gw we can remove all the gateway or a specific family ipv4/ipv6.

remove-gw dev [DEVICE] f|family [ipv4|ipv6|yes] Removes Gateway from device.        

Example:

Remove all GWs.

? nmctl remove-gw dev eth0
? nmctl show-config eth0
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Address]
Address=192.168.10.51/24

[Address]
Address=192.168.10.52/24

[Address]
Address=FE80::10        

  • Remove only GW of an explicit family i.e IPv4/IPv6

? nmctl set-gw-family dev eth0 gw4 192.168.10.1 gw6 FE80::1
? nmctl remove-gw dev eth0 family ipv4

? nmctl show-config eth0
/etc/systemd/network/10-eth0.network

[Match]
Name=eth0

[Address]
Address=192.168.10.51/24

[Address]
Address=192.168.10.52/24

[Address]
Address=FE80::10

[Route]
Gateway=fe80::1        

Adding address

? add-addr dev [DEVICE] address|a|addr [ADDRESS] peer [ADDRESS]] label [STRING] pref-lifetime|pl [{forever|infinity|0}] scope {global|link|host|NUMBER}] dad [DAD {none|ipv4|ipv6|both}] prefix-route|pr [PREFIXROUTE BOOLEAN] prefix-route|pr [PREFIXROUTE BOOLEAN] many [ADDRESS1,ADDRESS2...] Configures device Address.

? nmctl add-addr dev eth0 a 192.168.1.5        

  • Removing one address at a time

? nmctl remove-addr dev eth0 a 192.168.1.5        

  • Add many addresses at once

? nmctl add-addr dev eth0 many 192.168.1.5/24,192.168.1.6/24,192.168.1.7/24,192.168.1.8/24        

  • remove many addresses at once

? nmctl remove-addr dev eth0 many 192.168.1.5/24,192.168.1.6/24,192.168.1.7/24,192.168.1.8/24        

  • remove many addresses at once by family

? nmctl remove-addr dev eth0 family ipv4        

  • remove all addresses at once

? nmctl remove-addr dev eth0 family yes        

  • Adding one GW at a time

? set-gw dev [DEVICE] gw [GATEWAY ADDRESS] onlink [ONLINK BOOLEAN] Configures device default Gateway.

? nmctl set-gw dev eth0 gw 192.168.1.1 onlink yes        

The device status can be verified by status

? nmctl status eth0
                        Name: eth0
                       Index: 6
                       Group: 0
                       Flags: up broadcast running multicast lowerup
                        Type: ether
                        Path: pci-0000:02:01.0
                  Parent Dev: 0000:02:01.0
                  Parent Bus: pci
                      Driver: e1000
                      Vendor: Intel Corporation
                       Model: 82545EM Gigabit Ethernet Controller (Copper) (PRO/1000 MT Single Port Adapter)
                   Link File: /usr/lib/systemd/network/99-default.link
                Network File: /etc/systemd/network/10-eth0.network
                       State: routable (configured)
               Address State: routable
          IPv4 Address State: routable
          IPv6 Address State: degraded
                Online State: online
         Required for Online: yes
           Activation Policy: up
                  HW Address: 00:0c:29:5f:d1:39 (VMware, Inc.)
                         MTU: 1500 (min: 46 max: 16110)
                      Duplex: full
                       Speed: 1000
                       QDISC: fq_codel
              Queues (Tx/Rx): 1/1
             Tx Queue Length: 1000
IPv6 Address Generation Mode: eui64
                GSO Max Size: 65536 GSO Max Segments: 65535
                TSO Max Size: 65536 TSO Max Segments: 65535
                     Address: 192.168.10.51/24 (static)
                              fe80::10/128 (IPv6 Link Local)
                              192.168.10.52/24 (static)
                              fe80::4cc5:88ff:fe28:c1c0/64 (IPv6 Link Local)
                     Gateway: fe80::1 (static) (configuring,configured)
           DHCP6 Client DUID: DUID-EN/Vendor:0000ab11d258482fc7eee651        

GitHub repo network-config-manager.

Thanks !

要查看或添加评论,请登录

Susant Sahani的更多文章

社区洞察

其他会员也浏览了