Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to create linux namespaces

Shulou Source: shulou.com Published: 2022-05-31 13:31:46 09月16日 Update

This article introduces the knowledge of "how to create linux namespaces". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The system calls clone to add CLONE_NEWNET

Used to isolate network-related resources, which allows each network namespace to have its own network device, IP address, IP routing table, / proc/net directory, port number, and so on

From a network namespace perspective, each container has its own network device (virtual) and an application used to bind its own network port number. The appropriate routing rules on the host can associate network packets with network devices associated with a particular container. For example, you can have multiple web servers, each in a different container, which allows these web servers to bind 80 port numbers in their namespaces

Create a network space on the command line

/ var/run/netns

# ip netns add netns1

# ip netns exec netns1 ip link list

# ip netns delete netns1

Network device (physical or virtual interfaces, bridges)

Virtual network devices

Virtual ethernet or veth

Created, the lo loopback device

# ip netns exec netns1 ping 127.0.0.1

Connect: Network is unreachable

# ip netns exec netns1 ip link set dev lo up

# ip netns exec netns1 ping 127.0.0.1

PING 127.0.0.1 (127.0.0.1) 56 (84) bytes of data.

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.051 ms

# ip link add veth0 type veth peer name veth2

# ip link set veth2 netns netns1

# ip netns exec netns1 ifconfig veth2 10.1.1.1/24 up

# ifconfig veth0 10.1.1.2/24 up

# ping 10.1.1.1

# ip netns exec netns1 ping 10.1.1.2

# ip netns exec netns1 route

This is the end of "how to create linux namespaces". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Network space slogan network device device name content more server knowledge routing related service different appropriate practical learned next host command Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology Huawei Redmi Microsoft