【Linux学习】Linux垮网段访问
1.安装pptpd
[root@VM_0_6_centos etc]# yum install -y pptpd
2.对虚拟专用网络进行IP段分配
[root@VM_0_6_centos etc]# vim /etc/pptpd.conf
localip 193.112.40.37
remoteip 172.16.1.120-200
3.指定DNS写入文件末尾即可
[root@VM_0_6_centos etc]# vim /etc/ppp/options.pptpd
ms-dns 8.8.8.8
ms-dns 8.8.4.4
4.配置用户名和密码
[root@VM_0_6_centos etc]# vim /etc/ppp/chap-secrets
Secrets for authentication using CHAP
client server secret IP addresses
xingyulin pptpd 123456 *
5、开启IP转发
[root@VM_0_6_centos etc]# vim /etc/sysctl.conf
将“net.ipv4.ip_forward = 0”改为“net.ipv4.ip_forward = 1”
Controls IP packet forwarding
net.ipv4.ip_forward = 1
转发生效
[root@VM_0_6_centos etc]# sysctl -p
6.配置转发策略以及开放常用的端口
[root@VM_0_6_centos ppp]# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
[root@VM_0_6_centos ppp]# iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
[root@VM_0_6_centos ppp]# iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
[root@VM_0_6_centos ppp]# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
[root@VM_0_6_centos ppp]# iptables -A INPUT -p tcp -m tcp --dport 1723 -j ACCEPT
7、重启pptpd服务
[root@VM_0_6_centos etc]# systemctl start pptpd.service
检查状态active (running)为成功
[root@VM_0_6_centos etc]# systemctl status pptpd.service
● pptpd.service - PoPToP Point to Point Tunneling Server
Loaded: loaded (/usr/lib/systemd/system/pptpd.service; enabled; vendor preset: disabled)
Active: active (running) since 五 2019-01-04 11:15:53 CST; 4h 17min ago
Main PID: 19053 (pptpd)
CGroup: /system.slice/pptpd.service
└─19053 /usr/sbin/pptpd -f
8.链接虚拟专用网络测试
9.l2tp访问网络
安装软件
yum install -y epel-release
yum install -y NetworkManager-l2tp
nmcli connection add con-name VPNName type vpn vpn-type org.freedesktop.NetworkManager.l2tp ifname portName
cd /etc/NetworkManager/system-connections/
配置好VPN相关账户密码
重启网络配置
/etc/init.d/network restart
连接
nmcli connection up VPNName --ask