Article directory
overview
This document mainly records ubuntu
the configuration method of setting the static address of the network card and dual network card routing in the system.
system version
Ubuntu 20.04
Set a static IP address
1. View the network card name
ifconfig -a
2. Modify the network card configuration file
sudo vim /etc/netplan/00-installer-config.yaml
Note:
00-installer-config.yaml
The file name may be different, so modify it according to the actual situation.
3. Modify the content of the configuration file
# This is the network config written by 'subiquity'
network:
version: 2
renderer: networkd
ethernets:
enp0s3: # 网卡名称
dhcp4: yes
enp0s8: # 网卡名称
dhcp4: no
addresses: [192.168.1.101/24] # 静态IP地址
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1] # 网关地址
Note:
enp0s3
andenp0s8
is the name of the network card, which should be modified according to the actual situation.
4. Make the configuration file take effect
sudo netplan apply
Set up dual network card routing
1. Check the routing table
route -n
2. Add routing
sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1 dev enp0s3
Note: The above command is to add a default route, pointing to the Internet, the gateway address is
192.168.1.1
, and all data packetsenp0s3
are sent out through the network card.
3. Delete the route
sudo route del -net 0.0.0.0 dev enp0s3
Description: The above command is to delete the default route pointing to the Internet. All packets are
enp0s3
routed through the network card and deleted.