2021-08-11 Ubuntu 16.04 设置静态IP以及解决固定IP后ping不通外网的问题

一、设置静态IP步骤:

1、ifconfig查看目前的IP和获取网卡名,可以看出网卡名是eno1。

 2、这个时候测试一下ping 外网和ping内外,确保网络是通的。

 3、ubuntu 系统分配固定 ip 修改配置文件interfaces,输入 sudo vi /etc/network/interfaces

xxx@ubuntu:~$ sudo vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eno1
iface eno1 inet dhcp

4、按如下修改

5、配置说明

配置说明:

    auto ens33:使用的网络接口
    iface ens33 inet static:ens33这个接口,使用静态IP设置
    address 192.168.43.50:设置IP地址
    netmask 255.255.255.0:设置子网掩码
    gateway 192.168.43.1:设置网关


修改完之后,按ESC键,然后输入:qw即可保存并关闭文件

5、 然后reboot系统,得reboot,我测试过用命令行重启网络 systemctl restart networking,但是无效。

6、reboot后ifconfig查看ip,ip已经是修改成静态ip了。

二、按第一步修改配置文件interfaces后,可以ping内网,但是不能ping外网,提示ping: unknown host。

1、可以ping内网不能ping外网图。

 2、解决方法,DNS有问题成设置8.8.8.8,ps:尝试设置成跟gateway  一样,但是还是不能ping外网。

 3、然后执行下面命令重启网卡

xxx@ubuntu:~$ sudo /etc/init.d/networking restart
Restarting networking (via systemctl): networking.service.

或者

xxx@ubuntu:~$ sudo systemctl restart networking

4、测试ok,内外网都可以ping了

三、参考文章

https://blog.csdn.net/dengjiaorong6093/article/details/102228931?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_title~default-0.base&spm=1001.2101.3001.4242

https://www.jianshu.com/p/d808fa099edb

https://blog.csdn.net/lzhitwh/article/details/82773335

https://www.jb51.cc/ubuntu/497709.html

https://www.cnblogs.com/yunwangjun-python-520/p/10433378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值