Use the ip netns command in Linux to isolate the network port and configure the IP address

Use the ip netns command in Linux to isolate the network port and configure the IP address

1. Add the isolation marker:

ip netns add fd

2. Put the specified network card into isolation:

ip link set eth1 netns fd

3. Execute commands in an isolated environment:

ip netns exec fd ifconfig eth1 down
ip netns exec fd ifconfig eth1 up
ip netns exec fd ip addr add 192.168.1.2/24 dev eth1

4. If there are multiple network ports, you can directly connect two pairs of network ports, configure IP addresses in the same network segment, and perform a ping operation to verify whether the isolated network port IP address configuration is successful:

ping -I eth2 192.168.1.2

Knowledge point extension: Linux command to view IP address

I believe everyone would like to know how to check IP in Linux. Today, I will introduce to you the following commands for checking IP in Linux for your reference and study. The following is a detailed introduction.

ifconfig

Linux command to view IP address --ifconfig

The ifconfig command is used to view and change the address and parameters of the network interface

$ ifconfig -a 
lo0: flags=849 mtu 8232 
inet 127.0.0.1 netmask ff000000 
hme0: flags=863 mtu 1500 
inet 211.101.149.11 netmask ffffff00 broadcast 211.101.149.255 
ether 8:0:20:a7:4d:21

The system will display the name of the network interface, the status of the interface (up or down),

Interface IP address and mask information

To change the IP address of a network interface:

#ifconfig hme0 down 
#ifconfig hme0 211.101.149.233 netmask 255.255.255.0 up

First, use the down command parameter to temporarily stop the service of network interface hme0, then use the Linux ifconfig command to view ip to assign a new IP address and mask to the interface, and start the network interface service. You can also change the IP address of the machine by changing the value of the IP address in the file /etc/hosts and restarting the system.

/etc/hosts/: 211.101.149.11 sampdt defines the host name in /etc/hostname.hme0 and the IP address.

If the network card is changed/added, the system cannot automatically start the interface service. In this case, you need to manually create the network port service:

#ifconfig hme0 plumb

Linux can create a network port service for interface le0 by checking ip

Accordingly, use ifconfig with the unplumb parameter to stop the service and shut down the network.

netconfig is used to set the IP address

Summarize

The above is what I introduced to you about using the ip netns command to isolate network ports and configure IP addresses under Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Detailed tutorial on using pip command after Python installation under Linux

<<:  In-depth explanation of the locking mechanism in MySQL

>>:  JavaScript to implement dynamic digital clock

Recommend

Drop-down menu and sliding menu design examples

I found a lot of websites that use drop-down or sl...

Detailed process of implementing the 2048 mini game in WeChat applet

Rendering Example Code Today we are going to use ...

Detailed explanation of MySQL from getting started to giving up - installation

What you will learn 1. Software installation and ...

The concrete implementation of JavaScript exclusive thinking

In the previous blog, Xiao Xiong updated the meth...

Summary of some related operations of Linux scheduled tasks

I have searched various major websites and tested...

Using JavaScript in HTML

The <script> tag In HTML5, script has the f...

How to add Tomcat Server configuration to Eclipse

1. Window -> preferences to open the eclipse p...

How to deal with too many Docker logs causing the disk to fill up

I have a server with multiple docker containers d...

Vue shuttle box realizes up and down movement

This article example shares the specific code for...