How to get bridge support with /etc/network/interfaces? - linux

There are some linux distros, where it is possible to configure a bridge in /etc/network/interfaces. As explained for example here, it is enough to use this to form a bridge:
iface eth0 inet manual
iface eth1 inet manual
iface br0 inet dhcp
bridge_ports eth0 eth1
I am building a custom linux image using yocto. In my image this is not working. Yocto version is morty, which is already 3 years old.
So, what I need to do to get this functionality? Is it enough to get a newer version of the ifupdown package (I assume that this package provides this functionality)?
I installed the bridge-utils package, and I could add a bridge using brctl, as explained here:
brctl addbr br0
brctl addif br0 eth0 eth1
but I do not want to do it manually. I would like to do it by modifying /etc/network/interfaces, because then the changes are saved between reboots.

Do you use systemd?
If so, try a bbappend of systemd-machine-units, e.g.:
FILESEXTRAPATHS_prepend := "${THISDIR}/systemd-machine-units:"
SRC_URI += " \
file://10-eth0.network \
file://10-eth1.network \
"
do_install_append() {
for file in $(find ${WORKDIR} -maxdepth 1 -type f -name *.network); do
install -m 0644 "$file" ${D}${systemd_unitdir}/network/
done
}

Related

RTNETLINK answers: Device or resource busy; ifup: failed to bring up wlxf4f26d13b2bd

I'm trying to configure the network via /etc/network/interfaces here's my file:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug usb0
iface usb0 inet dhcp
# The wifi network interface
iface wlxf4f26d13b2bd inet manual
hwaddress ether 2a:bf:x9:53:38:9d
wpa-driver nl80211
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
but when I try to activate the device with ifup wlxf4f26d13b2bd I get:
> RTNETLINK answers: Device or resource busy ifup: failed to bring up
> wlxf4f26d13b2bd
I'm not using NetworkManager.
This is the verbose output of ifup:
ifup -v wlxf4f26d13b2bd
ifup: configuring interface wlxf4f26d13b2bd=wlxf4f26d13b2bd (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/macchanger
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
wpa_supplicant: terminating wpa_supplicant daemon via pidfile /run/wpa_supplicant.wlxf4f26d13b2bd.pid
Stopped /sbin/wpa_supplicant (pid 1568).
wpa_supplicant: removing /run/sendsigs.omit.d/wpasupplicant.wpa_supplicant.wlxf4f26d13b2bd.pid
wpa_supplicant: wait for wpa_cli to attach
wpa_supplicant: wpa-driver nl80211
wpa_supplicant: /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlxf4f26d13b2bd.pid -i wlxf4f26d13b2bd -W -D nl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf -C /run/wpa_supplicant
Starting /sbin/wpa_supplicant...
wpa_supplicant: creating sendsigs omission pidfile: /run/sendsigs.omit.d/wpasupplicant.wpa_supplicant.wlxf4f26d13b2bd.pid
wpa_supplicant: ctrl_interface socket located at /run/wpa_supplicant/wlxf4f26d13b2bd
/sbin/ip link set dev wlxf4f26d13b2bd address 2a:bf:x9:53:38:9d
RTNETLINK answers: Device or resource busy
ifup: failed to bring up wlxf4f26d13b2bd
I solved the issue. The problem was that it was trying to change the MAC address after the wpa_supplicant configuration; The order of commands in the file is not respected. The simple solution is either to set the mac address with pre-up macchanger -m inside the iface stanza or to invoke macchanger before wpa-supplicant.
Thanks!

Obtaining allowed MTU range for specific device from bash-script

How can one obtain MTU range supported by some network device in Linux from bash-script (not directly through netlink API)?
I tried to play with ifconfig and ip link but can't find the solution.
Package iproute2 (since v4.19) parses min/max mtu details and prints it to console when "--details" option is provided by user
ip --details link
ip --details link --name=eth0
ip --details addr
ip --details addr show dev eth0
example of script
#!/bin/bash
for nic in eth0 eth1 eth2; do
min_mtu=`ip --details link show $nic | grep 'minmtu'| sed -r 's/^(.*minmtu) ([0-9]+) (.*)$/\2/'`
max_mtu=`ip --details link show $nic | grep 'maxmtu'| sed -r 's/^(.*maxmtu) ([0-9]+) (.*)$/\2/'`
echo "$nic - min: $min_mtu, max: $max_mtu"
done
output:
eth0 - min: 60, max: 9000
eth1 - min: 68, max: 1770
eth2 - min: 68, max: 1770
Debian 10 already has recent enough version of iproute2 package (v4.20) to display min/max mtu.
Ubuntu 18.04.3 has a kernel which already provides this information to userspace but iproute2 package is not fresh enough(v4.15) to parse kernel's data (and display them to the user).
You can build fresh iproute2 tools yourself in case you have outdated package.
git clone git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
cd iproute2 && ./configure && make && ./ip/ip --details link

iproute2 commands for MPLS configuration

Trying to figure out how one can use iproute2 to manage static label-switched MPLS routes in Linux kernel 4.1.
I am aware iproute2 support for MPLS might be incomplete right now [2].
Can anyone please shed some light on what iproute2-4.1.1 is currently able to do?
This is what I have found so far:
Documentation/networking/mpls-sysctl.txt
/proc/sys/net/mpls/platform_labels
/proc/sys/net/mpls/conf//input
Load mpls module
sudo modprobe mpls_router
Find sysctl support
sysctl -a --pattern mpls
net.mpls.conf.eth0.input = 0
net.mpls.conf.eth1.input = 0
net.mpls.conf.lo.input = 0
net.mpls.platform_labels = 0
Enable mpls support
sudo sysctl -w net.mpls.conf.eth0.input=1
sudo sysctl -w net.mpls.conf.eth1.input=1
sudo sysctl -w net.mpls.platform_labels=1000
push??? (how to add prefix-to-push action?)
sudo ip route add 1.1.1.1/32 via mpls 100/200/300 dev eth0
swap??? (how to add label-swap action?)
sudo ip -f mpls route add 10 via mpls 100/200/300 dev eth0
pop??? (how to add label-pop action?)
???
show??? (how to display label-switched routes?)
???
Can someone help me out .
Thanks in Advance.
A little bit too late, but hope it helps somebody. You can find them here:
Routing 10.10.10.10/32 to 192.168.1.2 with label 100:
ip route add 10.10.10.10/32 encap mpls 100 via inet 192.168.1.2
Label swapping 100 for 200 and sent to 192.168.2.2:
ip -f mpls route add 100 as 200 via inet 192.168.2.2
Decapsulating label 300 and delivering locally:
ip -f mpls route add 300 dev lo
To show MPLS routes you can do:
ip -f mpls route show
If your iproute2 version doesn't support those commands, you can get it from here:
https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.6.0.tar.gz
And then
./configure && make && make install

Dynamic Switching of WiFi using a shell program in Raspberry Pi / Ubuntu / Debian

How can I check in a shell script, whether the system is connected to WiFi-1 and if not connected, connect to WiFi-2? I tried using wpa_supplicant and interfaces configurations, but not working as expected. I followed this tutorial
If there is any other way of doing this, please let me know.
/etc/network/interfaces file
auto eth0
iface eth0 inet6 manual
pre-up ip link set dev eth0 up || true
wpa-iface eth0
wpa-driver wired
wpa-conf /etc/wpa_supplicant/wpa_supplicant_wired.conf
pre-down /etc/netplug/netplug eth0 out >/dev/null 2>&1 || true
post-down ip link set dev eth0 down || true
auto wlan0
iface wlan0 inet manual
pre-up ip link set dev wlan0 up || true
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wpa-driver wext
pre-down /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
post-down ip link set dev wlan0 down || true
# open is specific (IPv6 only) so I just stop dhcp via netplug
iface open inet manual
up /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
iface default inet manual
up /etc/netplug/netplug wlan0 in >/dev/null 2>&1 || true
down /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
I think you may have already found the solution by now. Anyway as a workaround to do this you can install Network manager (supports all debian distributions including ubuntu/raspbian/etc)
sudo apt-get install network-manager
And then add required network configuration to /etc/NetworkManager/system-connections folder.
Sample configuration for a wifi network connection as follows:
[connection]
id=milanWiFi
uuid=56439211-1067-4334-b199-b73ceed32d83
type=802-11-wireless
[802-11-wireless]
ssid=milanWiFi
mode=infrastructure
mac-address=84:3A:4B:9B:CF:66
security=802-11-wireless-security
[802-11-wireless-security]
key-mgmt=wpa-psk
auth-alg=open
psk=milan123
[ipv4]
method=auto
[ipv6]
method=auto
Here, id is an unique name for your connection and you can obtain uuid by calling,
uuidgen command in the console.
For you to get the available wifi connections, you can use
sudo iw dev wlan0 scan
and there you can see the relevant details about the connections. What you have to do is to grab the details out of it and create the configuration file.

linux device driver for pure ipv6 device

I am currently designing a linux driver for a pure IPv6 driver. Is there any way to make the kernel module only support IPv6 and can only be assigned IPv6 address? What is the commands in linux to set the address?
Thanks
Adding IP:
Using ip command:
$sudo /sbin/ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0
Using ifconfig command:
$sudo /sbin/ifconfig eth0 inet6 add 2001:0db8:0:f101::1/64
Deleting IP:
Using ip
$sudo /sbin/ip -6 addr del 2001:0db8:0:f101::1/64 dev eth0
Using ifconfig
$sudo /sbin/ifconfig eth0 inet6 del 2001:0db8:0:f101::1/64

Resources