路由器的作用:用来NAT(地址解析)
网关:用于不同的网络互联
在Linux中配置IP地址的方法有以下这么几种:
ifconfig
命令临时配置IP地址(临时配置IP地址,即当我们重启计算机或重启网络服务后,配置将失效)setup
工具永久配置IP地址- 修改网络配置文件
ifconfig
命令
ifconfig
命令可以查看与配置网络状态,命令结果如下:
使用ifconfig
命令还可以临时设置某一网卡的IP地址和子网掩码。如:
网关的常用命令
查看网关:route -n
将真机伪装成路由器
重置路由器:firewall-cmd --reload
masquerade:yes 标示地址伪装功能开启,真实主机成为路由器
如果是no,则执行命令如下:firewall-cmd --add-masquerade
测试:
显示可以上网
但这个时候只能ping 地址,要想ping 名称,还需配置/etc/sysconfig/network-scripts/下的文件
配置如下:
这时就能直接用地址来ping了,结果显示:
dhcp设置
yum install dhcp -y
[root@localhost network-scripts]# yum install dhcp -y
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7.3 | 4.1 kB 00:00
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-47.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
dhcp x86_64 12:4.2.5-47.el7 rhel7.3 511 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 511 k
Installed size: 1.4 M
Downloading packages:
dhcp-4.2.5-47.el7.x86_64.rpm | 511 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 12:dhcp-4.2.5-47.el7.x86_64 1/1
rhel7.3/productid | 1.6 kB 00:00
Verifying : 12:dhcp-4.2.5-47.el7.x86_64 1/1
Installed:
dhcp.x86_64 12:4.2.5-47.el7
Complete!
[root@localhost network-scripts]#
设置客户端网卡工作模式为dhcp
vim /etc/sysconfig/network-scripts/ifcfg-eth3下配置BOOTPROTO =dhcp
重启网络:systemctl restart network
配置成功
防火墙配置:
开启防火墙:systemctl start firewalld
查看防火墙命令:systemctl status sys firewalld
关闭防火墙:systemctl stop firewalld