Under Linux use ip netns command to isolate the network port and configure ip address

  • 2021-07-01 08:30:37
  • OfStack

1. Add isolation markers:

ip netns add fd

2. Place 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. When there are multiple network ports, you can directly connect two pairs of network ports, configure the same network segment ip, perform ping operation, and verify whether the isolation network port ip configuration is successful:

ping -I eth2 192.168.1.2

Knowledge point extension: Linux view the command details of ip

I believe everyone knows the method of viewing ip in Linux. Today, I will introduce you an urgent command of viewing ip in Linux for your reference and study. The following is a specific 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 displays the name of the network interface, the status of the interface (up or down),

Information such as IP address and mask of interface

Change the IP address of the network interface:


#ifconfig hme0 down 
#ifconfig hme0 211.101.149.233 netmask 255.255.255.0 up 

First, use down command parameters to temporarily stop the service of network interface hme0, then use Linux command to view ip to assign new IP address and mask to the interface, and start the network interface service by changing files /etc/hosts And restart the system to change the machine's IP address.

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

The network card has been changed/added, and the system cannot automatically start the interface service. At this time, the network interface service needs to be created manually:

#ifconfig hme0 plumb 

Linux View ip to create network port service for interface le0

Accordingly, ifconfig with unplumb parameters can stop service and shut down the network.

netconfig is used to set the IP address

Summarize


Related articles: