How to Configure Networking in Photon OS from the Command Line

Changing the Hostname

To retrieve the current system hostname:

netmgr hostname --get

To set a new hostname:

netmgr hostname --set --name <hostname>

Configuring DNS Servers

Retrieve the Current DNS Servers

netmgr dns_servers --get

Set the DNS Mode and Servers

You can configure DNS to use either DHCP or a static mode and specify one or more DNS servers:

netmgr dns_servers --set --mode <dhcp|static> --servers <server1,server2,...>

Add a DNS Server

To add a new DNS server:

netmgr dns_servers --add --servers <server>

Remove a DNS Server

To remove a specific DNS server:

netmgr dns_servers --del --servers <server>

Note:
When modifying the DNS server list (such as when changing networks or decommissioning old DNS servers), it is recommended to remove the existing DNS servers first before adding new ones. This prevents exceeding the maximum number of DNS servers that can be registered to the SRM server or vSphere Replication appliance.


Configuring an IPv4 Address

Retrieve the Current IPv4 Address for an Interface

netmgr ip4_address --get --interface <ifname>

Set a New IPv4 Address

To assign a DHCP, static, or no IP address:

netmgr ip4_address --set --interface <ifname> --mode <dhcp|static|none> --addr <ipv4_address/prefix> --gateway <gateway_address>

Restarting Network Services

After making networking changes, restart the relevant services for the changes to take effect:

Restart the Network Service:

systemctl restart systemd-networkd

Restart the DNS Service:

systemctl restart systemd-resolved

🔥Subscribe to the channel: youtube.be/@AngryAdmin 🔥

🚨Dive into my blog: angrysysops.com

🚨Snapshots 101: a.co/d/fJVHo5v

🌐Connect with us:

💻Website: angrysysops.com

🔥vExpert info: vExpert Portal

Please leave the comment