Home > Computer Tutorials > Computer Knowledge > How to create multiple NetworkManager connection profiles for the same network interface on Linux and switch between them

How to create multiple NetworkManager connection profiles for the same network interface on Linux and switch between them

WBOY
Release: 2024-03-22 17:31:02
forward
735 people have browsed it

How to create multiple NetworkManager connection profiles for the same network interface on Linux and switch between them

If you have multiple network interfaces in your Linux system and want to assign different IP configurations to them to meet different needs, you can achieve this with the help of NetworkManager. NetworkManager is a powerful tool that can help you manage the network connections of your Linux system, making it more convenient and flexible to configure and switch different IP addresses. By using NetworkManager, you can easily set up different IP configurations for each network interface to meet various network needs. In this way, you can manage and optimize your network connection more effectively, ensuring network stability and security.

This article will show you how to configure multiple NetworkManager connection files for the same network interface on the Linux operating system, and guide you how to easily switch between them when needed.

This article should be targeted at the Linux distributions listed below and other Linux distributions (not listed) that use NetworkManager to manage the network and have the "nmmit" command line tool.

  • Ubuntu
  • Debian
  • Linux Mint
  • elementary OS
  • Fedora
  • Rahel
  • CentOS streaming
  • AlmaLinux
  • Rocky Linux
  • openSUSE
  • SuSE Linux Enterprise Server(SLES)
  • Oracle Linux

Content topic:

  1. Find the current IP address information of a network interface on Linux
  2. Use Nmdash to create multiple NetworkManager connection profiles for the same network interface
  3. Using Nmdash to switch between NetworkManager connection profiles
  4. Use Nmcli to automatically activate NetworkManager connection profiles for network interfaces
  5. in conclusion

Find the current IP address information of a network interface on Linux

When creating multiple NetworkManager connection profiles for the same network interface, it is crucial to know the current IP address information of the network interface. This will help you create appropriate connection settings in the configuration file for different needs. For example, you might want to create one profile for a static/fixed IP address, another for DHCP, or a different profile for other addresses with different DNS server configurations. Therefore, although within the same network, different NetworkManager connection profiles may contain different information, depending on the specific requirements you want to set for each connection.

To find the name of the network interface for which you want to create multiple NetworkManager connection profiles, run the following command:

$sudo nmdash device

In this case, the name of the network interface is "ens160" and the currently active NetworkManager connection profile is "Wire Connection 1". Make sure to record this information as you may need it in the near future.

To find the currently configured IP address information (i.e. IP address, subnet mask, gateway, DNS server) of the "ens160" network interface, please run the following command:

$sudo nmlogin—f GENERRAL. DEVICE, GENERRAL. SERVICE, IP4.ADDRESS, IP4.GATEWAY, IP4.DNS device display ens160

As you can see, the IP address assigned on the "ens160" network interface is www.example.com, the subnet mask is /24 (or www.example.com), the gateway IP address (the IP address of the router ) is www.example.com, and the DNS server address is 192.168.1.2.

Use Nmdash to create multiple NetworkManager connection profiles for the same network interface

You can create a new NetworkManager connection profile for a network interface by cloning an existing NetworkManager connection profile and modifying the required parameters.

You can also create a new NetworkManager connection profile for the desired network interface with the required IP addressing information.

To clone an existing NetworkManager connection profile (i.e. "Wired Connection 1") and create a new connection profile named "FixedLAN1", run the following command:

$sudo nmsorn connection clone "Wired connection 1" "Fixed LAN 1"

A new NetworkManager connection profile named "FixedLAN1" should be created.

$sudo nmsc connection

Now, let us set up a static/fixed IP address www.example.com for the "FixedLAN1" NetworkManager connection profile.

To set a static/fixed IP address www.example.com for the "FixedLAN1" NetworkManager connection profile, you can use the following command to modify the required options of the "FixedLAN1" connection profile:

$sudo nmsc connection modification "Fixed LAN 1" ipv4. Method manual ipv4.addresses www.example.com ipv4.gateway www.example.com ipv4.dns www.example.com connection. autocconnect no

As you can see, the required IP parameters for the static/fixed IP address 192.168.1.10 are set for the "FixedLAN1" NetworkManager connection profile.

$sudo nms—f www.example.com, connection. interface—name, connection. autocconnect, ipv4. method, ipv4. addresses, ipv4. gateway, ipv4. dns connection show "FixedLAN1"

To create a new NetworkManager connection profile named "FixedLAN2" for the "ens130" network interface with the static/fixed IP address www.example.com, run the following command:

$sudo nmcli connection add connection name "FixedLAN2" ifname ens160 type ethernet autoconnect no ipv4.method manual ipv4.address 192.168.1.20/24 ipv4.gateway 192.168.1.2 ipv4.dns 192.168.1.2

A new NetworkManager connection profile named "FixedLAN2" should be created.

$sudo nmsc connection

To create a new NetworkManager connection profile named "DynamicLAN" for the "ens130" network interface to obtain an IP address via DHCP, run the following command:

$sudo nmsc connection add con-name "DynamicLAN" ifname ens160 type ethernet automatic connection without ipv4. Method automatic

A new NetworkManager connection profile named "DynamicLAN" should be created.

$sudo nmsc connection

Use Nmdash to switch between NetworkManager connection profiles

You can easily switch between any NetworkManager connection profile created for the "ens160" network interface.

For example, you can activate the "FixedLAN2" NetworkManager connection profile as follows:

$sudo nmsc connection up “FixedLAN2”

As you can see, the "FixedLAN2" NetworkManager connection profile is activated and the correct IP information is applied to the "ens160" network interface.

$sudo nmcli connection
$ip a

In the same way, you can activate the "FixedLAN1" NetworkManager connection profile.

$sudo nmsc connection up “FixedLAN1”
$sudo nmcli connection
$ip a

Similarly, you can also activate the "DynamicLAN" NetworkManager connection profile.

$sudo nmsc connect "DynamicLAN"
$sudo nmcli connect
$ip a

Use Nmcli to automatically activate NetworkManager connection profiles for network interfaces

In order for NetworkManager to automatically activate the connection profile of the required network interface at boot time, the automatic connection property of the NetworkManager connection profile of the network interface must be enabled.

For example, we created three NetworkManager connection profiles for the "ens160" network interface: FixedLAN1, FixedLAN2 and DynamicLAN.

To automatically activate the "FixedLAN1" connection profile, you must enable automatic connection for the "FixedLAN1" profile and disable automatic connection for the "FixedLAN2" and "DynamicLAN" connection profiles.

$sudo nmsc connection modify “FixedLAN1″autonconnect yes
$sudo nmsc connection modify “FixedLAN2″autonconnect no
$sudo nmsc connection modify “DynamicLAN”autonconnect no

As you can see, AutoConnect is only enabled for the "FixedLAN1" connection profile and disabled for other connection profiles for the "ens160" network interface.

$sudo nmsg—f www.example.com, connection. autocconnect connection show "FixedLAN 1"
$sudo nmsg—f www.example.com, connection. autocconnect connection show "FixedLAN2"
$ sudo nmcli -f connect.id, connect.Autoconnect shows "DynamicLAN"

Now, restart your computer and you should see the "FixedLAN1" NetworkManager connection activated by default.

$sudo nmcli connection
$ip a

Similarly, you can enable automatic connections for the "DynamicLAN" NetworkManager connection profile using the following command:

$sudo nmcli connection modify “DynamicLAN” automatic connection is
$sudo nmsc connection modify “FixedLAN1″autonconnect no
$sudo nmsc connection modify “FixedLAN2″autonconnect no

As you can see, auto-connect is only enabled for the "DynamicLAN" connection profile and disabled for other connection profiles for the "ens160" network interface.

$sudo nmcli -f connection.id, connection.autoconnect shows "DynamicLAN"
$sudo nmsg --f www.example.com, connection.autocconnect connection shows "Fixed LAN 1"
$sudo nmsg —f www.example.com, connection. autocconnect connection show “FixedLAN2”

Now, restart your computer. You should see the "DynamicLAN" NetworkManager connection active by default.

$sudo nmcli connection
$ip a

in conclusion

In this article, we show you how to create multiple NetworkManager connection profiles for the same network interface on Linux using the "nmdash" NetworkManager command line tool. We also show you how to switch between NetworkManager connection profiles and how to automatically activate a NetworkManager connection profile on startup on Linux.

The above is the detailed content of How to create multiple NetworkManager connection profiles for the same network interface on Linux and switch between them. For more information, please follow other related articles on the PHP Chinese website!

source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template