Introduced back in 18.04, April 2018, networking was redone using a new system called Netplan – a YAML based configuration network configuration system for NetworkManager and SystemD.


/etc/netplan/00-installer-config.yaml

network:                            #indicates the beginning of the network configuration.
  version: 2			    #specifies the Netplan configuration version.
  renderer: networkd		    #determines which render as the network management tool.
  ethernets:                        #is the section where we define Ethernet interfaces.
      eth0:                         #is the names of the network interfaces we are configuring.
          addresses:                #is where we specify the static IP addresses for the interfaces.
              - 113.30.150.61/24           
          gateway4: 113.30.150.61   #is used to define the default gateway for the eth0 interface
          macaddress: 00:50:56:33:5a:30
          nameservers:              #is the section where we define DNS servers.
              addresses:                   
                  - 8.8.8.8
                  - 8.8.4.4
              search
                  - homenetworking.ir
         routes:
             - to: default          #sent all network packets through the following default gateway
               via: 113.30.150.254     

-The renderer concept in Netplan determines whether to use systemd-networkd or NetworkManager as the network management tool. It is specified in the /etc/netplan/*.yaml file and is crucial for efficient network management on Ubuntu 18.04 and above. Choosing systemd-networkd is suitable for static network environments, while selecting NetworkManager is more appropriate for dynamic network environments.

Network Manager strives for Network Connectivity, which “Just Works” for new Linux users. The machine should use the wired network connection when it’s plugged in but automatically switch to a wireless connection when the user unplugs it. Similarly, you can easily configure a VPN network and many other options.

-The search is a list of search domains, which are used when a non-fully qualified hostname is given. For example, if you were to ping server1 rather than server1.lab.


Configure IPv4 and IPv6

eth1:
          addresses:
               - 192.168.1.25/24
               - "2001:1::1/64"
          gateway4: 192.168.1.1
          gateway6: "2001:1::2"
          nameservers:
              addresses:
                  addressess: [8.8.8.8, "FEDC::1"]
                  search: [homenetworking.ir,lab]   

Applying the Configuration

# netplan apply

-If you encounter any issues, you can debug your configuration. This will provide more detailed output that can help identify any potential issues with the configuration.

#netplan --debug

This command generates backend-specific configuration files from /etc/netplan/*.yaml netplan configuration files. It essentially translates what you’ve written into a format that the selected renderer (either NetworkManager or networkd) can understand.

#netplan generate

Set WiFi Authentication

Systemd does not have native wifi support. In order for your network device to work with wifi you will need wpasupplicant installed.

ethernets:
  id0:
    [...]
    access-points:
      mode: infrastructure
      bssid: mywifi
      band: 5GHz
      channel: 5
    auth:
      key-management: none | psk | eap 
      password: my-password-string

mode set the mode type for your wifi network interface. For connecting to access points the value should be set to infrastructure, which is the default.

bassid is the name of your wifi connection, as configured on your access point.

band is used to set the wireless band. It accepts two values: 5GHz and 2.4GHz. If left unset, the wifi endpoint and your network device will automatically establish the best band. By setting this value you will force the connection to use a specific band.

channel is used to set your wifi channel, and only takes affect if the band property is set. 

*WPA and EAP connection modes accept the following configurations.

key-management sets how the supported key management mode. 
     none to disable key management 
     psk for WPA with pre-shared key, common for home wifi.
     eap for WPA with EAP, which is common for enterprise wifi networks.

password sets the pre-shared key or password for your wifi network, when the mode is set to either psk or eap.


Set Temporary addresses

#ifconfig eth0 192.168.1.4 netmask 255.255.255.0 broadcast 192.168.1.255

DNS

/etc/resolve.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

Routing

List main route table

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         113.30.150.254  0.0.0.0         UG    0      0        0 eth0
113.30.150.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
10.10.10.128    0.0.0.0         255.255.255.192 U     0      0        0 br0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo

Add/Delete Routes Temporary

# route add -host 10.10.10.129 dev eth1
# route add -net 10.10.10.128/26 dev eth0
# route add -net 172.16.10.1/24 gw 10.10.10.130
# route del -net 192.168.1.0/24 dev eth1
# route del default
# route add default gw 10.10.10.129 dev eth1

Leave a Reply

Your email address will not be published. Required fields are marked *