# Manual Ethernet Adapter Configuration ## Ubuntu * ``` cd /etc/netplan ``` * ``` ls ``` * You should see a **yaml** file, if it's not there you can create your own. * ``` cat *yaml ``` * By default it looks something like this : ``` # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ``` * Let's change this file ``` # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: enp34s0: dhcp4: yes ``` * Now if we run : * ``` sudo netplan generate ``` * ``` sudo netplan apply ``` * You will immediately notice your network adapter change. * Now this configuration applies **DHCP** to the adapter. * But, if we wanted to assign static **IP**, we would do the following configuration : ``` # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: enp34s0: dhcp4: no addresses: - 192.168.1.28/24 gateway4: 192.168.1.1 nameservers: addresses: - 8.8.8.8 ``` * Run the **netplan** commands * This will assign static IP **192.168.1.28** to that adapter. ### Bridged Network * Lets update the file to following file to this (assuming you have a network interface/adapter named **enp34s0**) ``` # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager ethernets: enp34s0: dhcp4: no dhcp6: no bridges: br0: interfaces: [enp34s0] addresses: [192.168.1.26/24] gateway4: 192.168.1.1 mtu: 1500 nameservers: addresses: [8.8.8.8] parameters: stp: true forward-delay: 4 dhcp4: no dhcp6: no ``` * Run the **netplan** commands * Run ```ip a``` * Now you should see changes in the adapter ### br0 ``` 8: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 2c:f0:5d:79:00:39 brd ff:ff:ff:ff:ff:ff inet 192.168.1.26/24 brd 192.168.1.255 scope global noprefixroute br0 valid_lft forever preferred_lft forever inet6 fe80::2ef0:5dff:fe79:39/64 scope link valid_lft forever preferred_lft forever ``` ### enp34s0 ``` 2: enp34s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000 link/ether 2c:f0:5d:79:00:39 brd ff:ff:ff:ff:ff:ff ``` **Useful Links :** 1. [Create Bridged Network](https://www.techrepublic.com/article/how-to-create-a-bridge-network-on-linux-with-netplan/) 2. [Delete Bridge Network](https://unix.stackexchange.com/questions/31763/bring-down-and-delete-bridge-interface-thats-up) --- ## CentOS * ``` cd /etc/sysconfig/network-scripts/ ``` * ``` ls ``` * You should see a file with this pattern ifcfg-* * ``` cat ifcfg-* ``` * By default it looks something like this : ``` TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=32ee6c07-273e-4bbd-8e85-3d7d6ce85c33 DEVICE=ens33 ONBOOT=yes ``` * Now if we run : * ```systemctl restart network``` It didn't work for me instead I ran the following ``` sudo ifconfig ens33 down ``` and ``` sudo ifconfig ens33 up ``` * This would apply DHCP on that adapter * But, if we wanted to assign static IP, we would do the following configuration : ``` TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33-test UUID=32ee6c07-273e-4bbd-8e85-3d7d6ce85c33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.1.23 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4 ``` * Restart Network * This will assign static IP **192.168.1.23** to that adapter. * If you notice, *BOOTPROTO* is now **static** * And the followings have been added to end of the document ``` IPADDR=192.168.1.23 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4 ``` [### Bridged Network * ```cd /etc/sysconfig/network-scripts/``` * ```sudo touch ifcfg-virbrN ``` here N can be any number in my case I have used ifcfg-virbr0 * Now Add the following to the file : ``` STP=yes BRIDGING_OPTS=priority=32768 TYPE=Bridge PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=virbr0-test UUID=44123894-8fb3-41a5-9a1e-ddf35d0ac9d1 DEVICE=virbr0 ONBOOT=yes IPADDR=192.168.1.25 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=8.8.8.8 DNS2=8.8.4.4 ``` * ```TYPE=Bridge``` is important. * Let's now change the **ifcfg-ens33** file to this : ``` TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes NAME=ens33-test UUID=32ee6c07-273e-4bbd-8e85-3d7d6ce85c33 DEVICE=ens33 ONBOOT=yes BRIDGE=virbr0 ``` * ```BOOTPROTO=none``` is important, also make sure that you have configured bridge like this ``` BRIDGE=virbr0 ```. Give the name according to your bridge network. * Now restart the network. * open up a terminal and run ```ip a ``` * Now you should see a new adapter named **virbr0** and it has all the IP configuration that you provided. * If you take a look at ens33 adapter you should now see that it has **virbr0** attached with it. ### virbr0 ``` 5: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 00:50:56:35:9a:3d brd ff:ff:ff:ff:ff:ff inet 192.168.1.25/24 brd 192.168.1.255 scope global noprefixroute virbr0 valid_lft forever preferred_lft forever inet6 fe80::9e2:cd05:8458:40c3/64 scope link noprefixroute valid_lft forever preferred_lft forever ``` ### ens33 ``` 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master virbr0 state UP group default qlen 1000 link/ether 00:50:56:35:9a:3d brd ff:ff:ff:ff:ff:ff ``` 1. [Create Bridge Network](https://www.golinuxcloud.com/how-to-configure-network-bridge-nmtui-linux/) 2. [Delete Bridge Network](https://unix.stackexchange.com/questions/31763/bring-down-and-delete-bridge-interface-thats-up)