Photon OS, developed by VMware, is a lightweight Linux distribution optimized for cloud-native applications. A key feature of Photon OS is its netmgr
utility—a command-line interface designed to streamline network configuration tasks. This article provides an in-depth exploration of netmgr
, covering its installation, syntax, and practical applications.
Introduction to netmgr
The netmgr
tool in Photon OS offers a command-line interface for managing network configurations. It supports operations such as setting IP addresses, configuring DNS servers, and managing network interfaces, making it an essential utility for system administrators.
Installation
netmgr
is included in the Photon OS distribution. To ensure you have the latest version, execute:
tdnf install netmgmt
This command uses Photon OS’s package manager, tdnf
, to install or update the netmgmt
package, which contains the netmgr
utility.
Syntax Overview
The netmgr
CLI follows a structured syntax based on the set
, get
, add
, and delete
command model. It utilizes an option-name and option-value format for specifying command parameters:
netmgr <network_object> <--get | --set | --add | --del> <command_options>
Here, <network_object>
represents the network component you intend to manage, such as link_info
, ip4_address
, or dns_servers
. The subsequent flags (--get
, --set
, --add
, --del
) determine the action to perform, followed by specific command options.
Managing Network Interfaces with netmgr
netmgr
provides comprehensive control over network interfaces. Below are examples of common tasks:
Viewing Interface Information
To retrieve details like MAC address, MTU, link state, and mode for a specific interface:
netmgr link_info --get --interface <ifname>
Replace <ifname>
with your interface name (e.g., eth0
).
Setting Interface Parameters
To configure various interface parameters:
- Set MAC Address:
netmgr link_info --set --interface <ifname> --macaddr <mac_address>
- Set Link Mode:
netmgr link_info --set --interface <ifname> --mode <manual|auto>
- Set Link State:
netmgr link_info --set --interface <ifname> --state <up|down>
- Set MTU:
netmgr link_info --set --interface <ifname> --mtu <mtu_value>
These commands allow precise control over interface configurations, facilitating network optimization.
Configuring IP Addresses
Managing IP addresses is a fundamental aspect of network configuration. netmgr
simplifies this process for both IPv4 and IPv6 addresses.
IPv4 Address Configuration
- Retrieve IPv4 Address:
netmgr ip4_address --get --interface <ifname>
- Set IPv4 Address:
netmgr ip4_address --set --interface <ifname> --mode <dhcp|static|none> --addr <ipv4_address/prefix> --gateway <gateway_address>
This command sets the IPv4 address, mode (DHCP, static, or none), and optionally the default gateway for the specified interface.
IPv6 Address Configuration
- Retrieve IPv6 Addresses:
netmgr ip6_address --get --interface <ifname>
- Add IPv6 Addresses:
netmgr ip6_address --add --interface <ifname> --addrlist <ipv6_addr1/prefix,ipv6_addr2/prefix,...>
- Delete IPv6 Addresses:
netmgr ip6_address --del --interface <ifname> --addrlist <ipv6_addr1/prefix,ipv6_addr2/prefix,...>
- Set IPv6 DHCP and Autoconfiguration:
netmgr ip6_address --set --interface <ifname> --dhcp <1|0> --autoconf <1|0>
These commands enable the addition, deletion, and configuration of IPv6 addresses and related settings.
Managing DNS Settings
Proper DNS configuration is crucial for network functionality. netmgr
facilitates DNS server and domain management.
- Retrieve DNS Servers:
netmgr dns_servers --get
- Set DNS Servers:
netmgr dns_servers --set --mode <dhcp|static> --servers <server1,server2,...>
- Add a DNS Server:
netmgr dns_servers --add --servers <server>
- Delete a DNS Server:
netmgr dns_servers --del --servers <server>
These commands allow you to view, set, add, and remove DNS servers as needed.
Additional Features
Beyond basic configurations, netmgr
offers advanced functionalities:
- Manage Static IP Routes:
- Retrieve routes:
netmgr ip_route --get --interface <ifname>
- Add a route:
netmgr ip_route --add --interface <ifname> --gateway <gateway_address> --destination <destination_network/prefix> --metric <N>
- Delete a route:
netmgr ip_route --del --interface <ifname> --destination <destination_network/prefix>
- Retrieve routes:
- Configure NTP Servers:
- Retrieve NTP servers:
netmgr ntp_servers --get
- Set NTP servers:
netmgr ntp_servers --set --servers <server1,server2,...>
- Add an NTP server:
netmgr ntp_servers --add --servers <server>
- Delete an NTP server:
netmgr ntp_servers --del --servers <server>
- Retrieve NTP servers:
Set System Hostname
netmgr hostname --set --name <hostname>
- Retrieve Current Hostname:
netmgr hostname --get
- Set Persistent Hostname:
netmgr hostname --set --persist <1|0>
These hostname management options are especially useful for ensuring network identity consistency in multi-node environments or cloud infrastructures.
Configuring Network Timeouts
Efficient network management sometimes requires tweaking timeouts for connection attempts or DHCP requests. The netmgr
utility allows you to set these parameters:
- Set Connection Timeout:
netmgr link_info --set --interface <ifname> --conn_timeout <timeout_value_in_seconds>
- Set DHCP Timeout:
netmgr ip4_address --set --interface <ifname> --dhcp_timeout <timeout_value_in_seconds>
These timeout settings help avoid delays and optimize network behavior in environments with specific latency requirements.
Practical Scenarios
Scenario 1: Configure a Static IP and DNS for a Server
Suppose you want to assign a static IP and custom DNS servers to eth0
for a server in a private network:
netmgr ip4_address --set --interface eth0 --mode static --addr 192.168.1.100/24 --gateway 192.168.1.1
netmgr dns_servers --set --mode static --servers 8.8.8.8,8.8.4.4
This sets a static IP (192.168.1.100
) with a /24
subnet and a default gateway of 192.168.1.1
. Google’s public DNS servers (8.8.8.8
and 8.8.4.4
) are configured for name resolution.
Scenario 2: Configure a Dual-Stack Interface with IPv4 and IPv6
For environments requiring both IPv4 and IPv6, use the following commands:
netmgr ip4_address --set --interface eth0 --mode dhcp
netmgr ip6_address --set --interface eth0 --dhcp 1 --autoconf 1
Here, IPv4 is dynamically assigned via DHCP, and IPv6 is configured to enable both DHCP and autoconfiguration.
Scenario 3: Add a Custom Route
To add a static route to a specific network (10.0.0.0/8
) via a gateway (192.168.1.254
) on eth0
:
netmgr ip_route --add --interface eth0 --gateway 192.168.1.254 --destination 10.0.0.0/8 --metric 100
This sets up a route with a custom metric value for priority in routing decisions.
Scenario 4: Automate DNS Updates for DHCP
If you want DNS updates to automatically synchronize with DHCP configurations:
netmgr dns_servers --set --mode dhcp
This ensures DNS servers are dynamically updated whenever the DHCP lease is renewed.
Debugging and Troubleshooting
Network issues can arise due to misconfigurations or environmental factors. The following commands can help debug and resolve these problems:
- Check Link State:
netmgr link_info --get --interface eth0
- Verify IP Configuration:
netmgr ip4_address --get --interface eth0
- Confirm DNS Server Settings:
netmgr dns_servers --get
- Examine Route Table:
netmgr ip_route --get --interface eth0
- Analyze NTP Settings:
netmgr ntp_servers --get
These commands provide immediate insights into the current network configuration and help pinpoint the root cause of issues.
Best Practices for Using netmgr
- Backup Configuration Files: Before making significant changes, backup network-related configuration files located in
/etc/systemd/network/
. - Test Configurations: Use the
--get
commands to verify settings after applying changes. - Combine Commands in Scripts: For consistent setups, script the
netmgr
commands and use them in automated deployment pipelines. - Monitor Logs: Check logs under
/var/log
for any errors related to networking ornetmgr
. - Keep
netmgr
Updated: Regularly update thenetmgmt
package to benefit from security patches and new features.
Conclusion
The netmgr
CLI in Photon OS is a powerful utility for network management, providing a straightforward interface for complex configurations. From basic IP settings to advanced routing and DNS management, netmgr
is indispensable for system administrators handling cloud-native environments. Whether you’re deploying a private server or managing a large-scale infrastructure, mastering netmgr
can streamline your workflow and ensure a robust network setup.
If you’re new to Photon OS or exploring its capabilities, start with netmgr
to configure and optimize your network infrastructure effectively.
🔥Subscribe to the channel: https://bit.ly/3vY16CT🔥
🚨Read my blog: https://angrysysops.com/
👊Twitter: https://twitter.com/AngrySysOps
👊Facebook: https://www.facebook.com/AngrySysOps
👊My Podcast: https://bit.ly/39fFnxm
👊Mastodon: https://techhub.social/@AngryAdmin