How to set up a bridge interface, add eth0 to it, and have internet connection
1
vote
1
answer
7539
views
I am trying to set up
br0
with eth0
and veth1
on a headless server where I am logged in via ssh
.
I am doing this as a preparation to run a systemd service in a special namespace. This namespace will have the peer of the virtual divice as it's endpoint: veth2
.
This should make it possible to set up static routes for just this process. In my case it will then route packages through a vpn
while all the other traffic goes to the standard gateway.
To figure out how this works I wrote a small script that executes the following so fast that the ssh
connection to the server does not break. I can then traceroute
the veth2
successfully. The server has just one eth
device and no wifi which is why I have to do it this way.
My problem is that after executing the script the server does not have internet access any more. I am probably missing a lot here. Can anyone help?
My script:
pi@testpi:~ $ cat add_bridge_and_veth1.sh
brctl addbr br0;
ip addr del 192.168.100.222/24 dev eth0;
ip addr add 192.168.100.222/24 dev br0;
brctl addif br0 eth0;
ip link set dev br0 up;
ip link add name veth1 type veth peer name veth2;
brctl addif br0 veth1;
brctl show;
ip netns add nsben1;
ip link set veth2 netns nsben1;
ip netns exec nsben1 ip addr add 192.168.55.101/24 dev veth2;
ip netns exec nsben1 ip link set lo up;
ip netns exec nsben1 ip link set veth2 up;
No internet after this in the default namespace:
pi@testpi:~ $ traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 192.168.100.222 (192.168.100.222) 3085.668 ms !H 3085.488 ms !H 3085.393 ms !H
pi@testpi:~ $ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 192.168.100.222 icmp_seq=1 Destination Host Unreachable
EDIT: My default setup is very simple. eth0
gets a fixed IP in 192.168.100.0/24
from the router according to the MAC
of the device: 192.168.100.222
.
pi@testpi:~ $ ip a
1: lo: 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: eth0: mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
link/ether b8:27:eb:98:70:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.100.222/24 brd 192.168.100.255 scope global dynamic noprefixroute eth0
valid_lft 83282sec preferred_lft 72482sec
inet6 fe80::247e:fd3c:36d7:68f5/64 scope link
valid_lft forever preferred_lft forever
3: br0: mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether b8:27:eb:98:70:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.100.222/24 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fe98:704b/64 scope link
valid_lft forever preferred_lft forever
5: veth1@if4: mtu 1500 qdisc noqueue master br0 state UP group default qlen 1000
link/ether e2:bc:58:01:67:92 brd ff:ff:ff:ff:ff:ff link-netns nsben1
inet 169.254.205.121/16 brd 169.254.255.255 scope global noprefixroute veth1
valid_lft forever preferred_lft forever
inet6 fe80::db71:b4e9:c60f:5865/64 scope link
valid_lft forever preferred_lft forever
No network in nsben1
, but this is not my main concern yet. I first want to have everything working in default namespace.
root@testpi:~# ip netns exec nsben1 ping 8.8.8.8
connect: Network is unreachable
Here the output for ip route
in default and nsben1
namespaces. I think Network is unreachable
from the nsben1
results from the internet beeing unreachable from default namespace. It does not necessarily mean that something is wrong with the nsben1
, but even if that's not the main problem at the moment.
root@testpi:~# ip route
192.168.55.0/24 dev veth2 proto kernel scope link src 192.168.55.101
root@testpi:~# ip route get 8.8.8.8
RTNETLINK answers: Network is unreachable
root@testpi:~# ip netns exec nsben1 ip route
192.168.55.0/24 dev veth2 proto kernel scope link src 192.168.55.101
root@testpi:~# ip netns exec nsben1 ip route get 8.8.8.8
RTNETLINK answers: Network is unreachable
For the sake of completeness ip a
in nsben1
:
root@testpi:~# ip netns exec nsben1 ip a
1: lo: 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
4: veth2@if5: mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 92:31:7e:0f:89:9d brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 192.168.55.101/24 scope global veth2
valid_lft forever preferred_lft forever
inet6 fe80::9031:7eff:fe0f:899d/64 scope link
valid_lft forever preferred_lft forever
------
**I tried @berndbausch's approach** of just executing the first five commands
brctl addbr br0;
ip addr del 192.168.100.222/24 dev eth0;
ip addr add 192.168.100.222/24 dev br0;
brctl addif br0 eth0;
ip link set dev br0 up;
in a script. When I do this I get the following output, where br0
and eth0
still have the same IP, which probably is wrong:
pi@testpi:~ $ sudo ./add_bridge.sh
pi@testpi:~ $ ip route
192.168.100.0/24 dev br0 proto kernel scope link src 192.168.100.222
pi@testpi:~ $ ip a
1: lo: 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: eth0: mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000
link/ether b8:27:eb:98:70:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.100.222/24 brd 192.168.100.255 scope global dynamic noprefixroute eth0
valid_lft 86389sec preferred_lft 75589sec
inet6 fe80::247e:fd3c:36d7:68f5/64 scope link
valid_lft forever preferred_lft forever
3: br0: mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether b8:27:eb:98:70:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.100.222/24 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fe98:704b/64 scope link
valid_lft forever preferred_lft forever
I then tried to execute the script adding ip link set dev eth0 down;
and up
like this:
ip link set dev eth0 down;
brctl addif br0 eth0;
ip link set dev eth up;
I lose the connection via ssh
which is understandable. Maybe it is normal that eth0
has the same IP as the br0
it is connected to. If not, why is the IP not removed despite me using ip addr del 192.168.100.222/24 dev eth0;
Asked by bomben
(549 rep)
Feb 10, 2021, 08:37 AM
Last activity: Feb 11, 2021, 11:56 AM
Last activity: Feb 11, 2021, 11:56 AM