ubuntu命令行怎么设置ip地址

avatar
作者
筋斗云
阅读量:0

在Ubuntu系统中,设置IP地址可以通过命令行使用ifconfigip命令来实现。以下是使用这两个命令设置IP地址的步骤:

使用ifconfig命令设置IP地址:

  1. 打开终端,输入以下命令查看当前网络接口的信息:
ifconfig 
  1. 找到需要设置IP地址的网络接口,通常是eth0enp0s3
  2. 输入以下命令设置IP地址(替换eth0为你的网络接口名,192.168.1.100为你要设置的IP地址):
sudo ifconfig eth0 192.168.1.100 
  1. 设置子网掩码(替换eth0为你的网络接口名,255.255.255.0为你的子网掩码):
sudo ifconfig eth0 netmask 255.255.255.0 
  1. 设置网关(替换192.168.1.1为你的网关地址):
sudo route add default gw 192.168.1.1 
  1. 如果需要设置DNS服务器,可以编辑/etc/resolv.conf文件:
sudo nano /etc/resolv.conf 

在文件中添加以下内容(替换为你的DNS服务器地址):

nameserver 8.8.8.8 nameserver 8.8.4.4 
  1. 重启网络服务使设置生效:
sudo service networking restart 

使用ip命令设置IP地址:

  1. 打开终端,输入以下命令查看当前网络接口的信息:
ip addr show 
  1. 找到需要设置IP地址的网络接口,通常是eth0enp0s3
  2. 输入以下命令设置IP地址(替换eth0为你的网络接口名,192.168.1.100为你要设置的IP地址):
sudo ip addr add 192.168.1.100/24 dev eth0 
  1. 设置网关(替换192.168.1.1为你的网关地址):
sudo ip route add default via 192.168.1.1 
  1. 如果需要设置DNS服务器,可以编辑/etc/resolv.conf文件(同上ifconfig设置步骤)。
  2. 重启网络服务使设置生效(同上ifconfig设置步骤)。

完成以上步骤后,你就成功设置了Ubuntu系统的IP地址。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!