How to use the command 'networkctl' (with examples)

How to use the command 'networkctl' (with examples)

The ’networkctl’ command is a powerful tool that allows users to manage network links and configurations using systemd-networkd. It provides various functions, such as querying the status of network links, bringing network devices up or down, renewing dynamic configurations, reloading configuration files, and reconfiguring network interfaces.

Code:

networkctl list

Motivation:

This use case is helpful when you want to get an overview of the network links available on your system and their current status. It allows you to quickly identify the active and inactive network interfaces.

Explanation:

The ’networkctl list’ command is used to display a list of all network links and their corresponding properties, including the interface index, state, type, hardware address, driver, and operational state.

Example output:

IDX    LINK             TYPE               OPERATIONAL SETUP
1      lo               loopback           carrier     unmanaged
2      enp0s31f6        ether              routable    configured
4      wlp3s0           wlan               no-carrier  unmanaged

In the example output above:

  • IDX refers to the interface index.
  • LINK represents the network link’s name.
  • TYPE indicates the type of network link.
  • OPERATIONAL shows the current operational state.
  • SETUP displays the setup state of the network link.

Use case 2: Show an overall network status

Code:

networkctl status

Motivation:

When you need a comprehensive view of your network configuration, the ’networkctl status’ command can be very useful. It provides an overview of all network links and their associated properties, including active IP addresses, assigned DHCP server, gateway, and DNS information.

Explanation:

The ’networkctl status’ command shows the overall network status, providing detailed information about each network link’s configuration and current state. It includes data such as IP addresses, routing tables, DNS servers, and more.

Example output:

● State: routable
   Address: 192.168.0.123 on enp0s31f6
   Gateway: 192.168.0.1 (Router)
...
● State: no-carrier
   Address: ---
   Gateway: ---
...

In the example output above:

  • State shows the current state of the network link.
  • Address displays the assigned IP address (if any).
  • Gateway indicates the default gateway.
  • Router refers to the router responsible for the network link.

Use case 3: Bring network devices up

Code:

networkctl up interface1 interface2 ...

Motivation:

You may want to bring network devices up manually to activate them if they are currently inactive. This use case is particularly relevant when troubleshooting network connectivity issues or when dealing with network interfaces that aren’t automatically activated.

Explanation:

The ’networkctl up’ command is used to bring network devices up. By providing the name(s) of the network interface(s) as arguments, you can manually activate them.

Example output:

Taking all network interfaces up...

In the example output above, the command successfully brought all network interfaces up.

Use case 4: Bring network devices down

Code:

networkctl down interface1 interface2 ...

Motivation:

When you want to deactivate specific network devices, the ’networkctl down’ command comes in handy. It allows you to bring network interfaces down, effectively disabling them.

Explanation:

The ’networkctl down’ command is used to bring network devices down. By providing the name(s) of the network interface(s) as arguments, you can manually deactivate them.

Example output:

Taking all network interfaces down...

In the example output above, the command successfully deactivated all network interfaces.

Use case 5: Renew dynamic configurations

Code:

networkctl renew interface1 interface2 ...

Motivation:

If your network configurations are obtained dynamically, such as IP addresses from a DHCP server, you might need to renew them manually. This use case allows you to refresh and acquire new network configurations.

Explanation:

The ’networkctl renew’ command is used to renew dynamic configurations. By specifying the name(s) of the network interface(s) as arguments, you can trigger the renewal process for these interfaces. This is especially useful if you want to acquire a new IP address from the DHCP server.

Example output:

Renewing configurations for interface enp0s31f6...

In the example output above, the command successfully renewed the configuration for the ’enp0s31f6’ interface.

Use case 6: Reload configuration files

Code:

networkctl reload

Motivation:

When you make changes to the network configuration files (.netdev and .network), you need to reload these changes for them to take effect. The ’networkctl reload’ command allows you to reload the configuration files.

Explanation:

The ’networkctl reload’ command is used to reload configuration files. By running this command, any modifications made to the network configuration files will be applied, ensuring that the new settings are active.

Example output:

Reloading configuration files...

In the example output above, the command successfully reloaded the configuration files.

Use case 7: Reconfigure network interfaces

Code:

networkctl reconfigure interface1 interface2 ...

Motivation:

If you make edits to the network interface configuration files and want your changes to take effect, you need to reconfigure the network interfaces. The ’networkctl reconfigure’ command allows you to do this.

Explanation:

The ’networkctl reconfigure’ command is used to reconfigure network interfaces. By specifying the name(s) of the network interface(s) as arguments, you can trigger the reconfiguration process. It is important to note that you should first call ’networkctl reload’ to apply any changes made to the interface configuration files.

Example output:

Reconfiguring interface enp0s31f6...

In the example output above, the command successfully reconfigured the ’enp0s31f6’ interface.

Conclusion:

The ’networkctl’ command is a versatile tool for managing network links and configurations. It provides a range of functionalities, such as querying the status of network links, managing network devices’ activation state, renewing dynamic configurations, and reloading or reconfiguring network interfaces. By understanding how to utilize ’networkctl’ effectively, you can easily monitor and control your network connections.

Related Posts

How to use the command 'betty' (with examples)

How to use the command 'betty' (with examples)

The betty command allows users to interact with their computer using natural language commands.

Read More
How to use the command 'shuf' (with examples)

How to use the command 'shuf' (with examples)

The ‘shuf’ command is a utility that generates random permutations. It can be used to randomize the order of lines in a file, generate random numbers within a specified range, and more.

Read More
Using Berkshelf Command (with examples)

Using Berkshelf Command (with examples)

Install cookbook dependencies into a local repo berks install Motivation: When working with Chef cookbooks, it is common to have dependencies on other cookbooks.

Read More