Hello Guys,
Just to expand on the previous post on configuring the R1 , here are some commands . I had originally planned to use ports 3 and 4 for in and out respectively , but for a neater cabling solution in my case I have gone with port 3 incoming and port 2 outgoing . Anyways here goes : SO to obtain two different networks on a device that has one NIC we need to use vlans , which R1 can do . To set up the interfaces we can use nmcli :
- Starting with host interface root@bananapi_r1 /home/user # nmcli con add type ethernet con-name eth0 ifname eth0
-vlan interfaces: root@bananapi_r1 /home/user # nmcli con add type vlan con-name eth0.101 ifname eth0.101 dev eth0 id 101 ip4 192.168.0.1/24 root@bananapi_r1 /home/user # nmcli con add type vlan con-name eth0.102 ifname eth0.102 dev eth0 id 102 ip4 192.168.1.1/24
root@bananapi_r1 /home/user # nmcli con NAME UUID TYPE DEVICE eth0.102 0765dd2d-ec31-4480-9423-6383ecae508c vlan eth0.102 eth0.101 5aafafd7-15c1-44f9-89f1-891e0dd035e9 vlan eth0.101 eth0 a51b2669-ff95-4958-95ed-b8eb17736b6d 802-3-ethernet --
now we need to configure the switch , we must enable vlan mode , then set up the ports for untagging on egress to the outside world , but with tagging towards the NIC . As we said earlier the switch is connected to the NIC via port 8 . One other thing is that the switch configuration is not permanent , it needs to be loaded in after every restart . So the best tool to use for this is NetworkManager Dispatcher service . For this all we need to do is deposit a file with our switch commands (sw-config script) into following dir and dispatcher will take care of the rest :
root@bananapi_r1 /home/user # cat /etc/NetworkManager/dispatcher.d/pre-up.d/sw-config #!/bin/bash
# VLAN config for BCM53125
/usr/local/bin/swconfig dev eth0 set reset /usr/local/bin/swconfig dev eth0 set enable_vlan 1 /usr/local/bin/swconfig dev eth0 vlan 101 set ports '3 8t' /usr/local/bin/swconfig dev eth0 vlan 102 set ports '2 8t' /usr/local/bin/swconfig dev eth0 set apply
The program that we use here "/usr/local/bin/swconfig" is a user-space app that we compiled from OpenWrt sources , and it goes with the driver b53 that we compiled into the kernel . So in the end it looks like this :
root@bananapi_r1 /home/user # ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ether 02:58:02:42:91:71 txqueuelen 1000 (Ethernet) RX packets 6298443 bytes 2501488219 (2.3 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5663918 bytes 1393155412 (1.2 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 117
eth0.101: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fdc1:4e49:af09:1:58:2ff:fe42:911a prefixlen 64 scopeid 0x0<global> inet 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::58:2ff:fe42:911a prefixlen 64 scopeid 0x20<link> ether 02:58:02:42:91:1a txqueuelen 0 (Ethernet) RX packets 3736354 bytes 5356105613 (4.9 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1682249 bytes 204645624 (195.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0.102: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fdc1:4e49:af09:1:58:2ff:fe42:911b prefixlen 64 scopeid 0x0<global> inet6 fe80::58:2ff:fe42:911b prefixlen 64 scopeid 0x20<link> ether 02:58:02:42:91:1b txqueuelen 0 (Ethernet) RX packets 1938781 bytes 1302040974 (1.2 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3980639 bytes 5460733992 (5.0 GiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Now you probably noticed that MAC addresses look a bit different on the two vlan interfaces , that was done to keep Network manager happy as it was trying to create local ipv6 adresses based on the MAC .There seems to be a limitation in NetworkManager when it comes to vlans . When it found out that both eth0.101 and eth0.102 ended up with the same ipv6 link local address (because both had same MAC address which they inherited from the host interface) , it kept spitting errors . So to make everybody happy , a manual addition was done on the ifcfg-eth0.101 and ifcfg-eth0.102 to add individual MAC addresses :
For 101 I added : MACADDR=02:58:02:42:91:1A
For 102 I added : MACADDR=02:58:02:42:91:1B
I used the same prefix form the original eth0 HWADDRESS and just changed the last octet . It makes the interfaces unique at layer 2 and removes any ambiguity . Also helps with programs such as dhcpd which I run on the R1 to communicate with LAN hosts .
Best Regards
Milorad