CentOS 7中网络设置图文详解(3)

虚拟网络接口是指共用一个网卡,同一网卡可以配多个IP地址,不管访问哪一个IP地址都能访问同一服务器。(当不想用虚拟网卡时直接禁用虚拟网卡即可)

ifconfig 接口名:序号 IP地址

[root@localhost ~]# ifconfig ens33:0 192.168.144.140 //在ens33网卡上添加虚拟网卡,序列号为0 [root@localhost ~]# ifconfig //查看网卡信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.144.133 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 653 bytes 512686 (500.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 373 bytes 39897 (38.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //创建的虚拟网卡 inet 192.168.144.140 netmask 255.255.255.0 broadcast 192.168.144.255 ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) ...//省略部分内容... 设置路由记录

添加到指定网段的路由记录

route add -net 网段地址 gw IP地址(网关)

删除到指定网段的路由记录

route del -net 网段地址

删除路由表中默认网关记录

route del default gw IP地址

向路由表中添加默认网关记录

route add default gw IP地址

[root@localhost ~]# route //查看路由表 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route add -net 192.168.100.0/24 gw 192.168.144.1 //添加网段 [root@localhost ~]# route //查看路由表是否添加网段 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.100.0 192.168.144.1 255.255.255.0 UG 0 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route del -net 192.168.100.0/24 //删除添加的网段 [root@localhost ~]# route //查看路由表,看添加的网段是否删除 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route add default gw 192.168.144.1 //添加默认网关 [root@localhost ~]# route //查看是否成功添加默认网关 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 0 0 0 ens33 default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 [root@localhost ~]# route del default gw 192.168.144.1 //删除添加的默认网关 [root@localhost ~]# route //查看路由表是否成功删除 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default gateway 0.0.0.0 UG 100 0 0 ens33 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 192.168.144.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33 主机名称配置文件

保存全局网络设置,主要包括主机名信息

/etc/sysconfig/network//etc/hostname

在CentOS 6中若要修改主机名可以执行“vim /etc/sysconfig/network”修改配置文件,而在CentOS 7中我们可以执行“vim /etc/hostname”就可以去修改主机名配置文件了。

[root@localhost ~]# vim /etc/hostname //进入编辑主机名配置文件 localhost.localdomain //当前主机名 如若修改可以直接在编辑器修改主机名 ~ ~ ~ ~ ~ ~ 域名解析配置文件

指定为本机体提供DNS解析的服务器地址(对改文件的修改将会立即生效)

/etc/resolv.conf

格式

nameserver IP地址

[root@localhost ~]# vim /etc/resolv.conf # Generated by NetworkManager search localdomain nameserver 192.168.144.2 ~ ~ ~ ~ 本地主机映射文件

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11658.html