开启防火墙服务 以前为了方便,把防火墙都关闭了,因为现在项目都比较重要,害怕受到攻击,所以为了安全性,现在需要将防火墙开启,接下来介绍一下步骤。 1, 首先查看防火墙状态:
1 |
firewall-cmd --state |
下图所示为关闭防火墙,接下来需要开启 2, 开启防火墙, 启动firewall:
1 |
systemctl start firewalld.service |
设置开机自启:
1 |
systemctl enable firewalld.service |
3, 重启防火墙:
1 |
systemctl restart firewalld.service |
4, 检查防火墙状态是否打开:
1 |
firewall-cmd --state |
如图显示已经打开 5, 查看防火墙设置开机自启是否成功:
1 |
systemctl is-enabled firewalld.service;echo $? |
如图所示,即为成功 以上就是开启防火墙相关步骤 开启特定端口 在开启防火墙之后,我们有些服务就会访问不到,是因为服务的相关端口没有打开。 在此以打开80端口为例 命令:
1 2 3 4 5 6 7 8 9 10 |
开端口命令:firewall-cmd --zone=public --add-port=80/tcp --permanent 重启防火墙:systemctl restart firewalld.service 命令含义: --zone #作用域 --add-port=80/tcp #添加端口,格式为:端口/通讯协议 --permanent #永久生效,没有此参数重启后失效 |
如图,可看到开启端口成功: 如果不放心,可以通过命令:
1 2 |
netstat -ntlp 或:firewall-cmd --list-ports |
查看开启的所有端口,具体如图 from:https://blog.csdn.net/zll_0405/article/details/81208606
View Details1、安装PPTP
1 |
yum install pptpd ppp |
2、配置文件
1 2 |
#修改dns信息 vim /etc/ppp/options.pptpd |
将它更改为你的dns服务地址(此处为百度和谷歌的dns)
1 2 |
ms-dns 180.76.76.76 ms-dns 8.8.8.8 |
3、vpn 账户密码
1 |
vim /etc/ppp/chap-secrets |
设置 VPN账号 + 服务类型 + VPN密码 + IP
1 2 3 4 |
# Secrets for authentication using CHAP # client server secret IP addresses 123 pptpd 012345 * 456 * 123456 * |
账户123密码012345 4、设置最大传输单元
1 2 |
vim /etc/ppp/ip-up 在命令符 [ -x /etc/ppp/ip-up.local ] && /etc/ppp/ip-up.local “$@” 后面添加 ifconfig ppp0 mtu 1472 |
5、配置pptp配置文件
1 2 3 4 5 |
vim /etc/pptpd.conf localip 192.168.0.1 remoteip 192.168.1.100-110 localip ---本机ip地址 remoteip ---分配给客户端的地址,一般是内网网段地址 |
6、打开内核的ip 转发功能
1 2 3 |
vim /etc/sysctl.conf 编辑配置文件,添加 net.ipv4.ip_forward = 1 的配置,保存后退出。 运行 sysctl -p 使修改后的参数生效。 |
7、设置开机启动
1 2 3 4 5 |
#重启PPTP服务 systemctl restart pptpd #配置开机自启 systemctl enable pptpd.service |
8、打开防火墙
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
开启47及1723端口: firewall-cmd --zone=public --add-port=47/tcp --permanent firewall-cmd --zone=public --add-port=1723/tcp --permanent 允许防火墙伪装IP: firewall-cmd --zone=public --add-masquerade 允许gre协议: firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -p gre -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 0 -p gre -j ACCEPT 设置规则允许数据包由eth0和ppp+接口中进出 firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i ppp+ -o eth0 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -i eth0 -o ppp+ -j ACCEPT 设置转发规则,从源地址发出的所有包都进行伪装,改变地址,由eth0发出:(192.168.0.0内网地址,子网地址前两位) firewall-cmd --permanent --direct --passthrough ipv4 -t nat -I POSTROUTING -o eth0 -j MASQUERADE -s 192.168.0.0/24 重启服务器: firewall-cmd --reload systemctl restart pptpd |
9、日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
1、上线日志 vim /etc/ppp/ip-up 在[ -x /etc/ppp/ip-up.local ] && /etc/ppp/ip-up.local "$@" 后加上 echo "$PEERNAME 分配IP: $5 登录IP: $6 登录时间: `date -d today +%F_%T`" >> /var/log/pptpd.log 2、下线日志 vim /etc/ppp/ip-down 在/etc/sysconfig/network-scripts/ifdown-post --realdevice ${REALDEVICE} \ ifcfg-${LOGDEVICE} 后加上 echo "$PEERNAME 下线IP: $6 下线时间: `date -d today +%F_%T`" >> /var/log/pptpd.log |
from:https://blog.csdn.net/h18733517027/article/details/94435182
View Details