sudo su
ip addr
1
2
3
4
5
| ip addr show
ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
|
ip route
1
2
3
| ip route add 10.20.30.0/24 via 192.168.1.254 dev eth0
ip route add default via 192.168.1.1 dev eth0
|
dns
更换源
https://www.cnblogs.com/Thenext/p/18430885
1
2
3
4
5
6
| # 更改为 阿里源
Types: deb deb-src
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: noble noble-security noble-updates noble-proposed noble-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
|
设置固定静态 IP
https://cloud.tencent.com/developer/article/2502346
apt-get install net-tools
1、查看网卡名称
执行命令:ifconfig ,默认都是 ens33,先记住 dhcp 自动分配的 ip 地址以及网关,dns 地址。
2、修改网卡配置信息
默认安装好 /etc/netplan/ 目录下有自带的一个 50-cloud-init.yaml 文件,如果不想动原始文件,直接新建一个 01-netcfg.yaml 文件,然后写入下面配置,此方式需要你把 50-cloud-init.yaml 文件中的网卡对应的 dhcp4 改成 false。
执行命令:sudo vim /etc/netplan/01-netcfg.yaml ,根据自己需要固定的信息实际填写:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| network:
version: 2
renderer: networkd
ethernets:
ens33: #修改为你的实际接口名字
dhcp4: no
addresses:
- 192.168.0.88/24 # 固定的ip地址
routes:
- to: default
via: 192.168.0.1 # 网关
nameservers:
addresses:
- 114.114.114.114 # dns2
- 8.8.8.8 # dns1
|
3、网卡生效
执行命令下面命令:
1
2
3
4
| sudo netplan apply # 应用网卡配置
sudo systemctl restart systemd-networkd # 重启网络
ip addr # 查看生效
ping www.baidu.com # 检查网络是否通
|