Ubuntu 18.04 network setting

Use Netplan

Put under directory ‘/etc/netplan/’.
example; 50-cloud-init.yaml
After Edit, command “netplan”  for checking option “netplan try” and for actual seting “netplan apply”.

To let the interface named ‘enp2s0’ get an address via DHCP:

network
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: true

To instead set a static IP address, use the addresses key, which takes a list of (IPv4 or IPv6), addresses along with the subnet prefix length (e.g. /24). Gateway and DNS information can be provided as well:

network:
    ethernets:
        enp2s0:
            dhcp4: no
            dhcp6: no
            addresses: [192.168.1.20/24]
            gateway4: 192.168.1.1
            nameservers:
                    addresses: [192.168.1.1]
#if use static route
            routes:
            - to: 192.168.11.0/24
                via: 192.168.1.254
    version: 2

Connecting to an open wireless network

Netplan easily supports connecting to an open wireless network (one that is not secured by a password), only requiring that the access point is defined:

network:
  version: 2
  wifis:
    wlp1s0:
      access-points:
        opennetwork: {}
      dhcp4: yes

Connecting to a WPA Personal wireless network

Wireless devices use the ‘wifis’ key and share the same configuration options with wired ethernet devices. The wireless access point name and password should also be specified:

network:
  version: 2
  renderer: networkd
  wifis:
    wlp2s0:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.21/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8]
      access-points:
        "network_ssid_name":
          password: "**********"

Connecting to WPA Enterprise wireless networks

It is also common to find wireless networks secured using WPA or WPA2 Enterprise, which requires additional authentication parameters.

For example, if the network is secured using WPA-EAP and TTLS:

network:
  version: 2
  wifis:
    wlp2s0:
      access-points:
        workplace:
          auth:
            key-management: eap
            method: ttls
            anonymous-identity: "@internal.ntools.net"
            identity: "man@internal.example.com"
            password: "sOPsw1Yas"
      dhcp4: yes

Using multiple addresses on a interface

The addresses key can take a list of addresses to assign to an interface:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 10.100.1.38/24
       - 10.100.1.39/24
     gateway4: 10.100.1.1

Interface aliases (e.g. eth0:0) are not supported.

Using multiple addresses with multiple gateways

Similar to the example above, interfaces with multiple addresses can be configured with multiple gateways.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
     addresses:
       - 9.0.0.9/24
       - 10.0.0.10/24
       - 11.0.0.11/24
     #gateway4:    # unset, since we configure routes below
     routes:
       - to: 0.0.0.0/0
         via: 9.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 10.0.0.1
         metric: 100
       - to: 0.0.0.0/0
         via: 11.0.0.1
         metric: 100

Configuring interface bonding

Bonding is configured by declaring a bond interface with a list of physical interfaces and a bonding mode. Below is an example of an active-backup bond that uses DHCP to obtain an address:

network:
bonds:
bond0:
addresses:
- 192.168.1.5/24
gateway4: 192.168.1.1
interfaces:
- enp1s0
- enp2s0
nameservers:
addresses:
- 192.168.1.1
search:
- ntools.net
parameters:
mode: balance-rr
primary: enp1s0
ethernets:
enp1s0: {}
enp2s0: {}
version: 2

Below is an example of a system acting as a router with various bonded interfaces and different types. Note the ‘optional: true’ key declarations that allow booting to occur without waiting for those interfaces to activate fully.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
    enp2s0:
      dhcp4: no
    enp3s0:
      dhcp4: no
      optional: true
    enp4s0:
      dhcp4: no
      optional: true
    enp5s0:
      dhcp4: no
      optional: true
    enp6s0:
      dhcp4: no
      optional: true
  bonds:
    bond-lan:
      interfaces: [enp2s0, enp3s0]
      addresses: [192.168.93.2/24]
      parameters:
        mode: 802.3ad
        mii-monitor-interval: 1
    bond-wan:
      interfaces: [enp1s0, enp4s0]
      addresses: [192.168.1.252/24]
      gateway4: 192.168.1.1
      nameservers:
        search: [ntools.net]
        addresses: [8.8.8.8, 8.8.4.4]
      parameters:
        mode: active-backup
        mii-monitor-interval: 1
        gratuitious-arp: 5
    bond-conntrack:
      interfaces: [enp5s0, enp6s0]
      addresses: [192.168.254.2/24]
      parameters:
        mode: balance-rr
        mii-monitor-interval: 1

Configuring network bridges

To create a very simple bridge consisting of a single device that uses DHCP, write:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - enp3s0

A more complex example, to get libvirtd to use a specific bridge with a tagged vlan, while continuing to provide an untagged interface as well would involve:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      dhcp4: true
  bridges:
    br0:
      addresses: [ 10.3.99.25/24 ]
      interfaces: [ vlan15 ]
  vlans:
    vlan15:
      accept-ra: no
      id: 15
      link: enp0s25

 

Proxy used

edit /etc/environment

example; LAN

http_proxy="http://192.168.1.1:8080/"
https_proxy="http://192.168.1.1:8080/"
no_proxy=localhost,127.0.0.1,192.168.0.0/16

 

example; external proxy

http_proxy="http://[user:password@]host.xxxx.net:8080/"
https_proxy="http://[user:password@]host.xxxx.net:8080/"
no_proxy=localhost,127.0.0.1,192.168.0.0/16