Created
September 25, 2024 19:08
-
-
Save ericwoud/dedbf647b978094fef99e831e54f0a0d to your computer and use it in GitHub Desktop.
Test scripts for setting up bridge/ipforward/vlan/802.1q/802.1ad/pppoe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| intf="eth1" | |
| o="$1" | |
| echo 1 >/proc/sys/net/ipv4/ip_forward | |
| echo 1 >/proc/sys/net/ipv4/conf/$intf/forwarding | |
| ip link set $intf up | |
| while kill -9 $(cat /run/ppp0.pid) 1>/dev/null 2>/dev/null; do sleep 0.1; done | |
| ip link set $intf down | |
| ip link set dev $intf mtu 1500 | |
| ip addr del 192.168.22.2/24 dev $intf 2> /dev/null | |
| ip addr del 192.168.1.8/24 dev $intf 2> /dev/null | |
| ip route del default 2> /dev/null | |
| ip link del ${intf}.10 2> /dev/null | |
| ip link del ${intf}.20 2> /dev/null | |
| ip link del ${intf}.10.20 2> /dev/null | |
| ip link set $intf up | |
| orig=$intf | |
| proto="" | |
| [[ "$o" == "qq" || "$o" == "ad" ]] && mtu="mtu 1504" || mtu="mtu 1500" | |
| [ -z "$o" ] && o="b" | |
| if [[ "$o" == "ad" ]]; then | |
| proto="protocol 802.1ad" | |
| o="qq" | |
| fi | |
| if [[ "$o" == "qq" ]]; then | |
| ip link add link $intf name ${intf}.10 type vlan $proto id 10 | |
| intf="${intf}.10" | |
| ip link set $intf up | |
| o="q" | |
| fi | |
| if [[ "$o" == "q" || "$o" == "qp" ]]; then | |
| ip link add link $intf name ${intf}.20 type vlan id 20 | |
| intf="${intf}.20" | |
| ip link set $intf up | |
| [[ "$o" == "qp" ]] && o="p" || o="i" | |
| fi | |
| if [[ "$o" == "i" ]]; then | |
| echo "SETUP: ipforward" | |
| echo "define wan = $intf" > /etc/systemd/network/eth1.nft | |
| systemctl start nftables | |
| ip link set $intf up | |
| ip link set dev $orig $mtu | |
| ip addr add 192.168.22.2/24 broadcast 192.168.22.255 dev $intf | |
| ip route add default via 192.168.22.1 dev $intf | |
| ip a show dev $intf; ip r | |
| elif [[ "$o" == "b" ]]; then | |
| echo "SETUP: bridged" | |
| echo "define wan = $intf" > /etc/systemd/network/eth1.nft | |
| systemctl start nftables | |
| ip link set $intf up | |
| ip addr add 192.168.1.8/24 broadcast 192.168.1.255 dev $intf | |
| ip route add default via 192.168.1.1 dev $intf | |
| ip a show dev $intf; ip r | |
| elif [[ "$o" == "p" ]]; then | |
| echo "SETUP: pppoe" | |
| if [ -z "$(cat /etc/ppp/chap-secrets | grep eric)" ]; then | |
| echo -e '\n"eric" * "1234" *' >>/etc/ppp/chap-secrets | |
| fi | |
| echo "define wan = ppp0" > /etc/systemd/network/eth1.nft | |
| systemctl start nftables | |
| arguments=( | |
| plugin /usr/lib/rp-pppoe/rp-pppoe.so nic-$intf | |
| persist | |
| holdoff 0 | |
| noauth | |
| remotename myisp | |
| name eric | |
| defaultroute | |
| noipdefault | |
| #nodetach | |
| noaccomp | |
| nodeflate | |
| noproxyarp | |
| nopcomp | |
| novj | |
| novjccomp | |
| lcp-echo-interval 10 | |
| ) | |
| pppd "${arguments[@]}" | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| intf="lan2" | |
| o="$1" | |
| echo 1 > /proc/sys/net/ipv4/ip_forward | |
| echo 1 > /proc/sys/net/ipv4/conf/brlan/forwarding | |
| echo 1 > /proc/sys/net/ipv4/conf/$intf/forwarding | |
| ip link set $intf up | |
| while kill -9 $(cat /run/pppoe-server.pid) 1>/dev/null 2>/dev/null; do sleep 0.1; done | |
| ip link set $intf down | |
| ip link set dev $intf mtu 1500 | |
| ip link set dev $intf nomaster 2> /dev/null | |
| ip route del 192.168.22.0/24 dev $intf 2> /dev/null | |
| ip route del 192.168.22.0/24 dev $intf.10 2> /dev/null | |
| ip route del 192.168.22.0/24 dev $intf.10.20 2> /dev/null | |
| ip addr del 192.168.22.1/24 dev $intf 2> /dev/null | |
| ip link del ${intf}.10 2> /dev/null | |
| ip link del ${intf}.20 2> /dev/null | |
| ip link del ${intf}.10.20 2> /dev/null | |
| ip link set $intf up | |
| orig=$intf | |
| proto="" | |
| [[ "$o" == "qq" || "$o" == "ad" ]] && mtu="mtu 1504" || mtu="mtu 1500" | |
| [ -z "$o" ] && o="b" | |
| if [[ "$o" == "ad" ]]; then | |
| proto="protocol 802.1ad" | |
| o="qq" | |
| fi | |
| if [[ "$o" == "qq" ]]; then | |
| ip link add link $intf name ${intf}.10 type vlan $proto id 10 | |
| intf="${intf}.10" | |
| ip link set $intf up | |
| o="q" | |
| fi | |
| if [[ "$o" == "q" || "$o" == "qp" ]]; then | |
| ip link add link $intf name ${intf}.20 type vlan id 20 | |
| intf="${intf}.20" | |
| ip link set $intf up | |
| [[ "$o" == "qp" ]] && o="p" || o="i" | |
| fi | |
| if [[ "$o" == "i" ]]; then | |
| echo "SETUP: ipforward" | |
| ip link set $intf up | |
| ip link set dev $orig $mtu | |
| ip addr add 192.168.22.1/24 broadcast 192.168.22.255 dev $intf | |
| ip route add 192.168.22.0/24 dev $intf | |
| ip a show dev $intf; ip r | |
| elif [[ "$o" == "b" ]]; then | |
| echo "SETUP: bridged" | |
| ip link set dev $intf master brlan | |
| bridge vlan add vid 2 dev $intf pvid untagged | |
| ip link set $intf up | |
| elif [[ "$o" == "p" ]]; then | |
| echo "SETUP: pppoe" | |
| if [ -z "$(cat /etc/ppp/chap-secrets | grep eric)" ]; then | |
| echo -e '\n"eric" * "1234" *' >>/etc/ppp/chap-secrets | |
| fi | |
| cat <<-EOF >/run/pppoe-server-options | |
| require-chap | |
| auth | |
| lcp-echo-interval 10 | |
| lcp-echo-failure 2 | |
| ms-dns 192.168.1.1 | |
| netmask 255.255.255.0 | |
| defaultroute | |
| noipdefault | |
| EOF | |
| pppoe-server -k -C isp -L 192.168.22.1 -R 192.168.22.2 -N 9 -I $intf \ | |
| -X /run/pppoe-server.pid -O /run/pppoe-server-options | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anyone interested, I've posted my test-setup scripts for testing all different kinds of network connections:
One script on a host that is most near to the internet connection, upstream.
One script for a host that is connected to the first host, down-stream.
The scripts assume that the selected interface
$intfis not managed by NetworkManager, systemd-networkd or any otherStart both scripts with the same argument, see script for argument options.
Not all very difficult to setup, but easy pppoe setup was not documented very well, so maybe this info can help more testers.
One may need to change some ip numbers, I published this more as an example then ready to go scripts.