$ sudo sysctl -w net.ipv4.ip_forward=1
$ sudo iptables -t nat -F
$ sudo iptables -t mangle -F
$ sudo iptables -F
$ sudo iptables -X
$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
networkinterface=`ip addr show | awk '/inet.*brd/{print $NF; exit}'`
ici : enp2s0
sudo ip addr flush dev $networkinterface
sudo ip link set $networkinterface up
sudo ip link add name br0 type bridge
sudo ip link set $networkinterface master br0
sudo ip addr add 192.168.1.3/24 dev br0
sudo ip link set br0 up
sudo ip route add default via 192.168.1.1
sudo ip tuntap add tap0 mode tap
sudo ip link set tap0 up
sudo ip link set tap0 master br0
$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
link/ether bc:5f:f4:2d:8a:ff brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 1e:9f:1f:8b:7c:b5 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::be5f:f4ff:fe2d:8aff/64 scope link
valid_lft forever preferred_lft forever
5: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
link/ether 1e:9f:1f:8b:7c:b5 brd ff:ff:ff:ff:ff:ff
inet6 fe80::1c9f:1fff:fe8b:7cb5/64 scope link
valid_lft forever preferred_lft forever
$ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.1e9f1f8b7cb5 no enp2s0
tap0
$ qemu-system-x86_64 -enable-kvm -m 2048 -display sdl -vga std -hda vda.img -smp 2 \
-netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no \
-device e1000,netdev=mynet0,mac=52:55:00:d1:55:01
util01@station66:~$ ping 192.168.1.100 -c 2
PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
64 bytes from 192.168.1.100: icmp_seq=1 ttl=64 time=0.474 ms
64 bytes from 192.168.1.100: icmp_seq=2 ttl=64 time=0.450 ms
--- 192.168.1.100 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1027ms
rtt min/avg/max/mdev = 0.450/0.462/0.474/0.012 ms
util01@station66:~$ ssh util01@192.168.1.100
util01@192.168.1.100's password:
...
Last login: Mon Jan 17 21:40:51 2022 from 192.168.1.3
util01@station01:~$
[Paramètres IPv4]
- Méthode : Manuel
- Adresses :
- Adresse : 192.168.1.100
- Masque de réseau : 24
- Passerelle : 192.168.1.1
- Serveur DNS : 8.8.8.8; 8.8.4.4
util01@station01:~$ ping 192.168.1.3 -c 2
PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data.
64 bytes from 192.168.1.3: icmp_seq=1 ttl=64 time=0.144 ms
64 bytes from 192.168.1.3: icmp_seq=2 ttl=64 time=0.359 ms
--- 192.168.1.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1007ms
rtt min/avg/max/mdev = 0.144/0.251/0.359/0.108 ms
util01@station01:~$ ssh util01@192.168.1.3
util01@192.168.1.3's password:
...
Last login: Mon Jan 17 21:41:52 2022 from 192.168.1.100
util01@station66:~$
util01@station01:~$ ping google.fr -c 2
PING google.fr (142.250.185.131) 56(84) bytes of data.
64 bytes from fra16s50-in-f3.1e100.net (142.250.185.131): icmp_seq=1 ttl=57 time=101 ms
64 bytes from fra16s50-in-f3.1e100.net (142.250.185.131): icmp_seq=2 ttl=57 time=122 ms
--- google.fr ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 101.174/111.749/122.325/10.580 ms