Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of adding multiple network cards to docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Clear the physical Nic ip address (192.168.1.22) and make it work at the link layer to receive all packets

Ip addr del 192.168.1.22/24 dev eth0 ip addr add 0.0.0.0 dev eth0

two。 Create a bridge br0 and add interface eth0 to br0

Ip link add br0 type bridge # ip link delete br0 ip link set br0 up # ip link set br0 down ip link set eth0 master br0 # ip link set eth0 nomaster

3. Start the container

Docker run-it-- name testns centos

After the container is started, a network card eth0 has been configured.

After that, we added another network card to the container with ip command.

4. Prepare the environment for ip netns (see man ip-netns):

Nspid=$ (docker inspect-f'{{.State.Pid}} 'testns) ln-s / proc/$ {nspid} / ns/net / var/run/netns/$ {nspid}

5. Create a pair of network ports tt0 and tt1

Ip link add tt0 type veth peer name tt1

Or directly ip link add type veth peer to create veth0,veth2

6. Add a network port to br0

Ip link set dev tt1 master br0 ip link set dev tt1 up

7. Add another port to the container testns and name it eth2 configure ip

Ip link set dev tt0 name eth2 netns ${nspid} ip netns exec ${nspid} ip link set dev eth2 up ip netns exec ${nspid} ip addr add 10.65.120.48 dev eth2 ip netns exec 16 dev eth2 ip netns exec ${nspid} ip addr add 10.65.120.494916 label eth2:1 dev eth2

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report