网关: 路由器上和客户主机处在同一个网段的ip叫做客户主机的网关
ip route add default via 172.25.254.130
ip route del default via 172.25.254.130
vim /etc/sysconfig/network
GATEWAY=172.25.254.130
在rhel8中
systemctl restart NetworkManager
nmcli connection down 链接名称
nmcli connection up 链接名称
在rhel7中
systemctl stop NetworkManager
systemctl restart network
systemctl start NetworkManager
vim /etc/sysconfig/network-scripts/ifcfg-westos
DEVICE=ensp1s0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.10
NETMASK=255.255.255.0
GATEWAY=172.25.254.130 ##网关
在rhel8中
systemctl restart NetworkManager
nmcli connection down 链接名称
nmcli connection up 链接名称
在rhel7中
systemctl stop NetworkManager
systemctl restart network
1.在rhel7中添加一块网卡使rhel7主机变成双网卡主机
##添加默认网关 ##删除默认网关
2.设定rhel7主机的两块网卡地址为: 网卡1:192.168.0.100(和windows主机处在统一个网段) 网卡2:172.25.254.100(rhel8主机处在统一个网段)
3.在rhel7中打开内核路由功能
[root@rhel7_node1 network-scripts]# sysctl -a |grep ip_forward
net.ipv4.ip_forward = 0 ##表示内核路由器功能未开启
.....
vim /etc/sysctl.conf
net.ipv4.ip_forward=1 ##开启内核路由功能
sysctl -p ##设定更改立即生效
4.在rhel7中打开地址伪装功能
systemctl start firewalld
[root@rhel7_node1 network-scripts]# firewall-cmd --list-all public (active)
target: default
icmp-block-inversion: no
interfaces: ens33 ens38 sources:
services: ssh dhcpv6-client ports:
protocols:
masquerade: no ##地址伪装功能未开启
forward-ports:
source-ports:
icmp-blocks:
rich rules:
```bash
[root@rhel7_node1 network-scripts]# firewall-cmd --permanent --add- masquerade
[root@rhel7_node1 network-scripts]# firewall-cmd --reload
#测试:
1.在rhel8中设定ip:172.25.254.10
ping 192.168.0.3 ##测试能否和windows主机通
##测试结果为不能
2.ip route add default via 172.25.254.100 ##添加本机网关为
72.25.254.100
3.route -n ##查询网关
[root@localhost ~]# route -n ##查询网关
ping 192.168.0.3 ##地址可以通信
##################################
dns: 负责作域名转换成ip这个工作的主机叫做dns服务器(地址解析)
vim /etc/resolv.conf ##dns服务器指向文件临时
nameserver 114.114.114.114 ##114.114.114.114 为电信dns服务器
ping www.baidu.com -----> /etc/resolv.conf ---->114.114.114.114 ----> www.baidu.com = 39.156.66.18
vim /etc/hosts ##叫做本地解析文件
39.156.66.18 www.baidu.com
vim /etc/sysconfig/network-scripts/ifcfg-ensp1s0
##dns的永久设定
1.设定主机ip和windows在一个网段
2.设定主机网关和windows相同
3.在windows中ping www.baiud.com 查看百度ip
4.在linux中ping 百度ip可以
5.在linux中ping www.baidu.com 不可以
6.编写/etc/hosts
39.156.66.18 www.baidu.com
ping www.baidu.com 可以
ping www.qq.com 不可以
7./etc/resolv.conf
nameserver 114.114.114.114
ping www.qq.com 可以
1.nmcli connection delete System\ ensp1s0
2.vim /etc/sysconfig/network-scripts/ifcfg-ensp1s0
DEVICE=ensp1s0
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
3.vim /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=westos
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.25.254.10 NETMASK=255.255.255.0 TYPE=Bridge
重启网络
[root@localhost ~]# bridge link show
2: ensp1s0:
5: virbr0-nic: