句型格式如下:routeadddefaultgw网段IP

添加完网段后,使用route命令查看:route-n

route -n 查看默认路由_route add default gw 网关IP_linux网络连接命令

可以看见,我们早已添加了一条默认路由qq linux,目的地址是0.0.0.0,网段是192.168.0.1。

4、添加DNS服务器添加完网段后,我们还须要设置DNS服务器,便于访问Internet上的服务器

我们可以使用resolv.conf文件来设置linux网络连接命令,该文件在/etc/目录下linux网络连接命令,文件的内容如下:nameserverDNS服务器IP

route add default gw 网关IP_route -n 查看默认路由_linux网络连接命令

在这文件上面加入须要的dns服务器地址诸如:nameserver8.8.8.8

第二种:通过图形界面配置:可以通过图形化的系统管理工具进行网路配置,如nmtui网路设置。

1、先步入系统后输入nmtui命令回车,步入图形化网路设置页面

2、选择编辑链接按回车步入以太网设置界面。(注意:使用那个网卡就配置那个网卡,通常都是eth0)

route add default gw 网关IP_linux网络连接命令_route -n 查看默认路由

2、选择编辑链接按回车步入以太网设置界面。(注意:使用那个网卡就配置那个网卡,通常都是eth0)

route -n 查看默认路由_route add default gw 网关IP_linux网络连接命令

linux网络连接命令_route -n 查看默认路由_route add default gw 网关IP

route add default gw 网关IP_route -n 查看默认路由_linux网络连接命令

把IPv4改为自动linux 软件,在选择显示。(根究需求添加或更改相应的内容,)之后点击确定

linux网络连接命令_route -n 查看默认路由_route add default gw 网关IP

详尽信息如右图:

route add default gw 网关IP_route -n 查看默认路由_linux网络连接命令

点击返回

route add default gw 网关IP_route -n 查看默认路由_linux网络连接命令

route -n 查看默认路由_route add default gw 网关IP_linux网络连接命令

点击确定回到命输入页面。

route add default gw 网关IP_linux网络连接命令_route -n 查看默认路由

在命令行页面输入:servicenetworkrestart重启网路服务(不重启配置不会生效)

第三种、通过配置文件配置:可以直接编辑网路配置文件进行配置,如/etc/sysconfig/network-scripts/ifcfg-eth0文件。

命令vim/etc/sysconfig/network-scripts/ifcfg-eth0

route -n 查看默认路由_linux网络连接命令_route add default gw 网关IP

配置文件解读

设备类型:TYPE=Ethernet

地址分配模式:BOOTPROTO=static

网卡名称:NAME=eno16777736

是否启动:ONBOOT=yes

IP地址:IPADDR=192.168.10.10

子网网段:NETMASK=255.255.255.0

网段地址:GATEWAY=192.168.10.1

DNS地址:DNS1=192.168.10.1

在实际应用中,可以依照需求选择以上方式进行配置。

Tagged:
Author

这篇优质的内容由TA贡献而来

刘遄

《Linux就该这么学》书籍作者,RHCA认证架构师,教育学(计算机专业硕士)。

发表回复