Ubuntu networking: Difference between revisions

From Lolly's Wiki
Jump to navigationJump to search
m (Text replacement - "<source" to "<syntaxhighlight")
Line 6: Line 6:
===Create /etc/sysctl.d/60-disable-ipv6.conf===
===Create /etc/sysctl.d/60-disable-ipv6.conf===
Create a file named <i>/etc/sysctl.d/60-disable-ipv6.conf</i> with this content:
Create a file named <i>/etc/sysctl.d/60-disable-ipv6.conf</i> with this content:
<source lang=bash>
<syntaxhighlight lang=bash>
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
Line 13: Line 13:


===Activate /etc/sysctl.d/60-disable-ipv6.conf===
===Activate /etc/sysctl.d/60-disable-ipv6.conf===
<source lang=bash>
<syntaxhighlight lang=bash>
# sysctl -p /etc/sysctl.d/10-disable-ipv6.conf
# sysctl -p /etc/sysctl.d/10-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.all.disable_ipv6 = 1
Line 21: Line 21:


===Check settings===
===Check settings===
<source lang=bash>
<syntaxhighlight lang=bash>
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
# cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
1
Line 29: Line 29:
===Configure bond manually===
===Configure bond manually===
Specify your environment
Specify your environment
<source lang=bash>
<syntaxhighlight lang=bash>
# mymaster1=eno5
# mymaster1=eno5
# mymaster2=eno6
# mymaster2=eno6
Line 39: Line 39:


Create the bonding interface out of the two masters
Create the bonding interface out of the two masters
<source lang=bash>
<syntaxhighlight lang=bash>
# ip link add ${myinterface} type bond
# ip link add ${myinterface} type bond
# ip link set ${myinterface} type bond miimon 100 mode active-backup
# ip link set ${myinterface} type bond miimon 100 mode active-backup
Line 49: Line 49:


If you want to add a VLAN to your interface
If you want to add a VLAN to your interface
<source lang=bash>
<syntaxhighlight lang=bash>
# myvlan=1234
# myvlan=1234
# ip link add link ${myinterface} name ${myinterface}.${myvlan} type vlan id ${myvlan}
# ip link add link ${myinterface} name ${myinterface}.${myvlan} type vlan id ${myvlan}
Line 56: Line 56:


Bring your interface up and set yout ip address
Bring your interface up and set yout ip address
<source lang=bash>
<syntaxhighlight lang=bash>
# ip link set ${myinterface} up
# ip link set ${myinterface} up
# ip addr add ${myipaddr} dev ${myinterface}
# ip addr add ${myipaddr} dev ${myinterface}
Line 62: Line 62:


Set your default gateway and DNS
Set your default gateway and DNS
<source lang=bash>
<syntaxhighlight lang=bash>
# ip route add default via ${mygateway}
# ip route add default via ${mygateway}
# if (( ${#mynameservers[*]} > 1 )) ; then eval systemd-resolve --interface ${myinterface} --set-dns={$(IFS=,; printf '%s' "${mynameservers[*]}")} ; else eval systemd-resolve --interface ${myinterface} --set-dns=${mynameservers[0]} ; fi
# if (( ${#mynameservers[*]} > 1 )) ; then eval systemd-resolve --interface ${myinterface} --set-dns={$(IFS=,; printf '%s' "${mynameservers[*]}")} ; else eval systemd-resolve --interface ${myinterface} --set-dns=${mynameservers[0]} ; fi
Line 69: Line 69:
===ipa===
===ipa===
This is not only indian pale ale! On linux  
This is not only indian pale ale! On linux  
<source lang=bash>
<syntaxhighlight lang=bash>
# ip a
# ip a
</source>
</source>
Line 77: Line 77:
===iplishup===
===iplishup===
This just sounds like a word and helps you to keep it in mind.
This just sounds like a word and helps you to keep it in mind.
<source lang=bash>
<syntaxhighlight lang=bash>
# ip li sh up
# ip li sh up
</source>
</source>
Line 90: Line 90:
====netplan <command>====
====netplan <command>====
To apply changes to your files in /etc/netplan without reboot use:
To apply changes to your files in /etc/netplan without reboot use:
<source lang=bash>
<syntaxhighlight lang=bash>
# netplan appy
# netplan appy
</source>
</source>
Line 97: Line 97:
====DHCP====
====DHCP====
<i>/etc/netplan/ens160.yaml</i>
<i>/etc/netplan/ens160.yaml</i>
<source lang=yaml>
<syntaxhighlight lang=yaml>
network:
network:
   ethernets:
   ethernets:
Line 107: Line 107:
====Bonding====
====Bonding====
<i>/etc/netplan/bond007.yaml</i>
<i>/etc/netplan/bond007.yaml</i>
<source lang=yaml>
<syntaxhighlight lang=yaml>
network:
network:
   version: 2
   version: 2

Revision as of 16:52, 25 November 2021

Networking Networking

Disable IPv6

Create /etc/sysctl.d/60-disable-ipv6.conf

Create a file named /etc/sysctl.d/60-disable-ipv6.conf with this content: <syntaxhighlight lang=bash> net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 </source>

Activate /etc/sysctl.d/60-disable-ipv6.conf

<syntaxhighlight lang=bash>

  1. sysctl -p /etc/sysctl.d/10-disable-ipv6.conf

net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 </source>

Check settings

<syntaxhighlight lang=bash>

  1. cat /proc/sys/net/ipv6/conf/all/disable_ipv6

1 </source>

The ip command

Configure bond manually

Specify your environment <syntaxhighlight lang=bash>

  1. mymaster1=eno5
  2. mymaster2=eno6
  3. myinterface=bond007
  4. myipaddr=172.16.78.9/24
  5. mygateway=172.16.78.1
  6. declare -a mynameservers=( 172.16.77.4 172.16.79.4 )

</source>

Create the bonding interface out of the two masters <syntaxhighlight lang=bash>

  1. ip link add ${myinterface} type bond
  2. ip link set ${myinterface} type bond miimon 100 mode active-backup
  3. ip link set ${mymaster1} down
  4. ip link set ${mymaster1} master ${myinterface}
  5. ip link set ${mymaster2} down
  6. ip link set ${mymaster2} master ${myinterface}

</source>

If you want to add a VLAN to your interface <syntaxhighlight lang=bash>

  1. myvlan=1234
  2. ip link add link ${myinterface} name ${myinterface}.${myvlan} type vlan id ${myvlan}
  3. myinterface=${myinterface}.${myvlan}

</source>

Bring your interface up and set yout ip address <syntaxhighlight lang=bash>

  1. ip link set ${myinterface} up
  2. ip addr add ${myipaddr} dev ${myinterface}

</source>

Set your default gateway and DNS <syntaxhighlight lang=bash>

  1. ip route add default via ${mygateway}
  2. if (( ${#mynameservers[*]} > 1 )) ; then eval systemd-resolve --interface ${myinterface} --set-dns={$(IFS=,; printf '%s' "${mynameservers[*]}")} ; else eval systemd-resolve --interface ${myinterface} --set-dns=${mynameservers[0]} ; fi

</source>

ipa

This is not only indian pale ale! On linux <syntaxhighlight lang=bash>

  1. ip a

</source> shows you the configured addresses. It is the short cut for "ip address show".

iplishup

This just sounds like a word and helps you to keep it in mind. <syntaxhighlight lang=bash>

  1. ip li sh up

</source> shows you all links (interfaces) that are up. This is short for "ip link show up".

New since Ubuntu 17.10

netplan

Former configuration in /etc/network/interfaces{,.d} is now found in /etc/netplan in YAML syntax. The name of the file is /etc/netplan/<whatever you want, I prefer the interface name>.yaml . The .yaml at the end is not optional!

netplan <command>

To apply changes to your files in /etc/netplan without reboot use: <syntaxhighlight lang=bash>

  1. netplan appy

</source> Keep in mind: You might lose your connection depending on the changes made!

DHCP

/etc/netplan/ens160.yaml <syntaxhighlight lang=yaml> network:

 ethernets:
   ens160:
     dhcp4: yes
 version: 2

</source>

Bonding

/etc/netplan/bond007.yaml <syntaxhighlight lang=yaml> network:

 version: 2
 renderer: networkd
 ethernets:
   slave1:
     match:
       macaddress: "3c:a7:2a:22:af:70"
     dhcp4: no
   slave2:
     match:
       macaddress: "3c:a7:2a:22:af:71"
     dhcp4: no
 bonds:
   bond007:
     interfaces:
       - slave1
       - slave2
     parameters:
       mode: balance-rr
       mii-monitor-interval: 10
     dhcp4: no
     addresses:
       - 192.168.189.202/27
     gateway4: 192.168.189.193
     nameservers:
         search: 
           - mcs.de
         addresses:
           - "192.168.3.60"
           - "192.168.3.61"

</source>