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

Quickly learn MySQL basics

Table of contents Understanding SQL Understanding...

Detailed explanation of tcpdump command examples in Linux

Preface To put it simply, tcpdump is a packet ana...

Vue+js click arrow to switch pictures

This article example shares the specific code of ...

MySQL transaction, isolation level and lock usage example analysis

This article uses examples to describe MySQL tran...

Teach you to quickly build a web cluster project based on nginx

Table of contents 1. Project Environment 2. Proje...

Bootstrap realizes the effect of carousel

This article shares the specific code of Bootstra...

The principles and defects of MySQL full-text indexing

MySQL full-text index is a special index that gen...

MySQL Null can cause 5 problems (all fatal)

Table of contents 1. Count data is lost Solution ...

Detailed process of upgrading glibc dynamic library in centos 6.9

glibc is the libc library released by gnu, that i...

Shtml Concise Tutorial

Shtml and asp are similar. In files named shtml, s...

A detailed tutorial on using Docker to build a complete development environment

Introduction to DNMP DNMP (Docker + Nginx + MySQL...

How to import js configuration file on Vue server

Table of contents background accomplish Supplemen...

Specific use of useRef in React

I believe that people who have experience with Re...