管理网络
一、Ip基础知识
1、ipv4
2进制32位-----10进制
172.25.0.10/255.255.255.0
172.25.0.10:ip地址
255.255.255.0:子网掩码
子网掩码255位对应的ip位为网络位
子网掩码0对应的ip位为主机位
2、配置ip
《图形化》
1.图形界面
nm-connection-editor
2.文本化图形
nmtui
二、命令
ifconfig 网卡 ip netmask ##临时设定
nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes #添加dhcp网络
nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24 #添加静态网络
nmcli connection delete westos #删除westos链接
nmcli connection show #显示所有网络链接
nmcli connection down westos #关闭指定链接
nmcli connection up westos #开启指定链接
nmcli connection modify "westos" ipv4.addresses newip/24 #改变wetos的ip
nmcli connection modify "westos" ipv4.method <auto|manual> #改变westos的工作方式为动态或者静态
nmcli device connect eth0 #开启设备
nmcli device disconnect eth0 #关闭设备
nmcli device show #显示设备信息
nmcli device status #显示设备状态
三、文件
static|none ##静态网络
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 ##设备
BOOTPROTO=static|none ##设备工作方式
ONBOOT=yes ##开启网络服务激活设备
NAME=eth0 ##网络接口名称
IPADDR=172.25.0.100 ##IP
NETMASK=255.255.255.0 | PREFIX=24 ##子网掩码
3、网关
1.路由器
主要功能是用来作nat的
dnat 目的地地址转换
snat 源地址转换
2.网关
路由器上和自己处在同一个网段的那个ip
(真机ip:172.25.254.73,虚拟机ip 设置为172.25.254.171,使得真机与虚拟机处于同一个网段,才可通信)
*****进行地址包装*****
在真机里进行地址伪变换,使得虚拟机可以进行联网systemctl start firewalld
systemctl enable firewalld
firewall-cmd --permanent --add-masquerade
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=192.168.0.127 masquerade'
firewall-cmd --reload
用firewall-cmd --list-all查看是否伪装成功
3、设定网关
(1)设置全局网关
systemctl stop NetwrokManager
vim /etc/sysconfig/network
GATEWAY=网关ipa (此时虚拟机已经可以联网,但没有设置dns,只能用ip地址上网,网关为172.25.254.73)
2、(网卡接口网关)
vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件 ##网卡接口网关
GATEWAY=网关ip
语句执行后一定要重启服务(systemctl restart network)
查询网关(route -n)
显示结果:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 (网关)172.25.0.254 0.0.0.0 UG 0 0 0 eth0
172.25.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
5、dns
dns是一台服务器
这台服务器提供了回答客户主机名和ip对应关系的功能
(2)设置dns
查看真机/etc/resolv.conf
后写入虚拟机/etc/resolv.conf
vim /etc/resolv.conf
设置dns后,ping ww.baidu.com可以连接
也可设置网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件
(3)本地解析文件
vim /etc/hosts
(4)本地解析文件和dns读取的优先级调整
vim /etc/nsswitch.conf
38 #hosts: db files nisplus nis dns
39 hosts: files dns ##files代表本地解析文件,dns代表dns服务器,那个在前面那个优先