Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of adding multiple network cards to docker

Shulou Source: shulou.com Published: 2022-06-02 03:46:09 09月23日 Update

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.

Tags: Container network card network port configuration content command address that is interface data physics environment link plus one bridge preparation reference study work help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Shulou Technology Microsoft vpn