如何用命令行在Ubuntu20.04修改系统IP地址

1. 修改配置文件

打开 配置IP的文件 路径如下

sudo vi /etc/netplan/01-network-manager-all.yaml

1.1 输入(修改)以下内容

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens0:
      dhcp4: false
      addresses: [192.168.1.123/24]
      gateway4: 192.168.1.1
    ens1:
      dhcp4: false
      addresses: [192.168.1.124/24]
      gateway4: 192.168.1.1
  version: 2

注意: 这是修改为静态IP的方式,所以上面的 DHCP4:最好改成 FALSE,防止自动获取IP,导致IP又变了

1.2 示例如下

如何用命令行在Ubuntu20.04修改系统IP地址

1.3 更新网络设置

/etc/init.d/openibd restart

2. 命令行修改 ifconfig – route

根据ifconfig 命令,这个命令一般系统自带,也可以后期安装
sudo apt install net-tools

2.1 先找到需要修改的网卡

ifconfig

如何用命令行在Ubuntu20.04修改系统IP地址

2.2 输入设置IP命令

sudo ifconfig ens33 192.168.1.123/24 up

大体格式如下:
sudo权限 ifconfig 网卡名 IP地址/掩码 up

2.3 输入设置网关命令

sudo route add default gw 192.168.1.1

格式:
sudo权限 route add default gw 网关地址

1.3 更新网络设置

— ifconfig 修改 — end —

由于 ifconfig 在Ubuntu 里大部分是通过后期安装 net-tools 包,安装上的 ,刚安装完的系统可能没有这个 net-tools 包,所以 ifconfig 命令无法使用
但 ip 命令是 自带的

3. 命令行修改 ip link – ip route
3.1 找到需要设置的网卡

ip a 或 ip addr

如何用命令行在Ubuntu20.04修改系统IP地址

(一毛一样,毕竟是一个命令…..哈哈)

3.2 设置ip地址 及 路由

ip link set eth0 up # eth0 是前面的 网卡端口名
ip link show eth0 # 这个 eth0 也是
ip addr add <ip地址> dev eth0 # 这个也是
ip route add default via <网关>
</ip地址>

— ip link – ip route — end —

© 版权声明
THE END
喜欢就支持一下吧
点赞15赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容