Network Namespace

MySprtlty·2024년 1월 16일
0

Linux

목록 보기
10/10

Network Namespace: blue
How to Use Linux Network Namespace

Network Namespace

  • Linux network namespaces are a Linux kernel feature allowing us to isolate network environments through virtualization.
  • For example, using network namespaces, you can create separate network interfaces and routing tables that are isolated from the rest of the system and operate independently.
  • To understand namespaces easily, it is worth saying Linux namespaces are the basis of container technologies like Docker or Kubernetes.
  • Linux includes 6 types of namespaces: pid, net, uts, mnt, ipc, and user. This tutorial focuses on Linux network namespaces.

1. Linux Namespace 출력

  • lsns
    • stands for LiSt NameSpace

2. Adding a Linux Network Namespace

  • ip netns add blue

3. Network Namespace 목록 확인

  • ip netns

4. Network Namespace 명령

  • To run commands within a network namespace, the syntax is the following.
  • ip netns exec <NameSpace> <command>
    • ex) ip netns exec blue ip link set dev lo up
    • ex) ip netns exec blue /bin/login
      • 해당 namespace에 로그인

5. Show Network Namespace Interface

  • ip netns exec blue ip address

6. Ping Namespace's Interface

  • ip netns exec blue ping 127.0.0.1
    • ping blue's loopback interface

7. Virtual Ethernet (veth)

  • Associate a hardware network card to your namespace, or you can add virtual network devices.
  • By adding virtual network interfaces, you can allow connectivity between different namespaces.
  • Virtual network devices are named veth (Virtual Ethernet Device).
  • Network Namespace에는 오직 veth(Virtual Ethernet)만 할당 가능하다
  • veth는 튜브(양방향 파이프)처럼 항상 pairs(쌍)으로 만들어진다.
  • 쌍으로 만들어진 한쪽 veth는 name space에 두고 다른 한쪽 veth를 다른 namespace에 두면, 두 네임스페이스 간에 통신이 가능하다.

8. Create veth

  • ip link add veth0 type veth peer name veth1

9. veth 쌍 출력

  • ip link list

10. Assign veth(Virtual Device)to NameSpace

  • ip link set veth1 netns blue

11. Assign an ip address to the new network device

  • ip -n blue addr add 10.0.1.0/24 dev veth1

12. veth up

  • ip -n blue link set veth1 up

13. Namespace에서 veth 찾기

  • ip netns exec blue ip link list

14. Namespace Interface 설정

  • ip netns exec blue ifconfig veth1 10.1.1.1/24 up

15. Namespace 네트워크 정보 출력

  • ip netns exec blue sudo ifconfig
profile
2Co 4:7

0개의 댓글