在本地主机映射文件中添加映射记录,当访问添加的记录网站时,将会直接向添加的映射记录IP地址发送web请求,省略了向DNS服务器解析IP地址的过程。
保存主机名与IP地址的映射记录
/etc/hosts
hosts文件和DNS服务器的比较
默认情况下,系统首先从hosts文件查找解析记录
hosts文件只对当前的主机有效
hosts文件可减少DNS查询过程,从而加快访问速度
补充内容: 双网卡的建立在日常生产活动中难免会遇到需要建立双网卡的情况,这里我们来看看如何建立双网卡
1、首先在虚拟机Linux操作系统中添加一块物理网卡,然后查看网络接口信息,确定是否成功添加网络
[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 3415 bytes 740748 (723.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1725 bytes 201799 (197.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //新添加的物理网卡 inet 192.168.144.141 netmask 255.255.255.0 broadcast 192.168.144.255 inet6 fe80::deb1:3cec:3e26:5ec2 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet) RX packets 85 bytes 6069 (5.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 30 bytes 4667 (4.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 02、这个时候我们查看网卡配置文件目录,看是否有添加的网卡配置文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/ //进入网卡配置文件目录 [root@localhost network-scripts]# ls //查看,这个时候时没有新添加的网卡ens36的配置文件的 ifcfg-ens33 ifdown-ipv6 ifdown-TeamPort ifup-ippp ifup-routes network-functions ifcfg-lo ifdown-isdn ifdown-tunnel ifup-ipv6 ifup-sit network-functions-ipv6 ifdown ifdown-post ifup ifup-isdn ifup-Team ifdown-bnep ifdown-ppp ifup-aliases ifup-plip ifup-TeamPort ifdown-eth ifdown-routes ifup-bnep ifup-plusb ifup-tunnel ifdown-ib ifdown-sit ifup-eth ifup-post ifup-wireless ifdown-ippp ifdown-Team ifup-ib ifup-ppp init.ipv6-global3、因为没有ens36网卡的配置文件,我们就没有办法给ens36指定固定的地址的。下面我们就把ens36与ens33这两个网卡全部设为仅主机相连模式,然后再查看网络接口信息。
[root@localhost ~]# ifconfig //查看网络接口信息 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //无获取IP地址 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3578 bytes 754392 (736.7 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1812 bytes 215065 (210.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //无发获取IP地址 inet6 fe80::deb1:3cec:3e26:5ec2 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:aa txqueuelen 1000 (Ethernet) RX packets 160 bytes 12321 (12.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 48 bytes 7865 (7.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0我在这里无法获取IP地址是因为的VMware虚拟机中DHCP服务关掉了,所以无法获取地址。
4、这个时候我们就给这两个物理网卡配固定地址
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //编辑网卡信息 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static //dhcp更改为static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=2ef6b862-5201-48c5-a450-23b3720ab3a0 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.100.10 //输入配置IP地址 NETMAS=255.255.255.0 //输入配置子网掩码 GATEWAY=192.168.100.0 //输入配置网关 ~ ~ ~ ~ ~ ~ ~ :wq [root@localhost ~]# service network restart //重启网络服务 Restarting network (via systemctl): [ 确定 ] [root@localhost ~]# ifconfig //查看网络接口信息,看配置的地址是否生效 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.100.10 netmask 255.255.255.0 broadcast 192.168.100.255 inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link> ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet) RX packets 3642 bytes 771191 (753.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1948 bytes 239617 (234.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0