centos iptables 开机启动 centos镜像
大家好,今天小编来为大家解答centos iptables 开机启动这个问题,centos镜像很多人还不知道,现在让我们一起来看看吧!
Centos7 开启 iptables 日志
Netfilter/Iptables(简称Iptables)是Unix/Linux系统自带的优秀且完全免费的基于包过滤的防火墙工具,其功能强大,使用灵活,能够对流入、流出及流经服务器的数据包进行精细控制。
在实际生产环境中,有时可能需要对特定数据包进行过滤。然而,在复杂的网络环境中,可能出现收不到正常的数据报文的情况。这时,查看数据报文是否被Iptables过滤导致无法接收就显得尤为重要。
下面介绍如何开启Iptables日志,以进行数据报文情况的查看:
首先,在rsyslog.conf中添加配置:
# vim/etc/rsyslog.conf
在文件中添加以下行:
kern.*/var/log/iptables.log
随后重启日志配置:
# systemctl restart rsyslog.service
接着,若需让日志滚动,可在配置文件中添加如下行:
# vim/etc/logrotate.d/syslog
添加以下行:
/var/log/iptables
在Iptables配置中添加日志选项,以测试配置是否生效:
# iptables-A INPUT-j LOG--log-prefix"iptables"
检查日志文件是否生成:
# tailf/var/log/iptables.log
完成测试后,删除测试链:
# iptables-D INPUT-j LOG--log-prefix"iptables"
清空Iptables日志文件:
# echo"">/var/log/iptables.log
此方法能够帮助用户追踪数据包过滤情况,提高网络管理效率。
Linux上PPTPVPN的一键安装以及设置开机启动的方法
设置pptp vpn开机启动
有的人懒的重启后手动开启服务,所以下面我再补上开机自动启动pptp vpn和 iptables的命令
复制代码代码如下:#chkconfig pptpd on//开机启动pptp vpn服务
#chkconfig iptables on//开机启动iptables
贴个openvz的pptp vpn一件安装包吧:centos,fedora,redhat 6.x使用的脚本(vps上从没安装过的可以试试这个脚本):点击下载
复制代码代码如下:#!/bin/bash
# Interactive pptp vpn install script for an OpenVZ VPS
# surport: Cenost,Fedora 6.x
# Augest 24, 2014 v1.00
#url:
echo"######################################################"
echo"Interactive PoPToP Install Script for an OpenVZ VPS"
echo
echo"Make sure to contact your provider and have them enable"
echo"IPtables and ppp modules prior to setting up PoPToP."
echo"PPP can also be enabled from SolusVM."
echo
echo"You need to set up the server before creating more users."
echo"A separate user is required per connection or machine."
echo"######################################################"
echo
echo
echo"######################################################"
echo"Select on option:"
echo"1) Set up new PoPToP server AND create one user"
echo"2) Create additional users"
echo"######################################################"
read x
if test$x-eq 1; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
## get the VPS IP
#ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
echo
echo"######################################################"
echo"Downloading and Installing ppp and pptpd"
echo"######################################################"
yum install ppp-y
rpm-Uvh
yum install pptpd-y
echo
echo"######################################################"
echo"Creating Server Config"
echo"######################################################"
cp/etc/ppp/options.pptpd/etc/ppp/options.pptpd.bak
sed-i'70a ms-dns 8.8.8.8'/etc/ppp/options.pptpd
# setting up pptpd.conf
sed-i'101a localip 192.168.9.1'/etc/pptpd.conf
sed-i'102a remoteip 192.168.9.11-30'/etc/pptpd.conf
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Forwarding IPv4 and Enabling it on boot"
echo"######################################################"
cat>>/etc/sysctl.conf<<END
net.ipv4.ip_forward=1
END
sysctl-p
echo
echo"######################################################"
echo"Updating IPtables Routing and Enabling it on boot"
echo"######################################################"
iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE
# saves iptables routing rules and enables them on-boot
iptables-save>/etc/iptables.conf
cat>/etc/network/if-pre-up.d/iptables<<END
#!/bin/sh
iptables-restore</etc/iptables.conf
END
chmod+x/etc/network/if-pre-up.d/iptables
cat>>/etc/ppp/ip-up<<END
ifconfig ppp0 mtu 1400
END
echo
echo"######################################################"
echo"Restarting PoPToP"
echo"######################################################"
sleep 5
/etc/init.d/pptpd restart
echo
echo"######################################################"
echo"Server setup complete!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
# runs this if option 2 is selected
elif test$x-eq 2; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Addtional user added!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
else
echo"Invalid selection, quitting."
exit
fi
#!/bin/bash
# Interactive pptp vpn install script for an OpenVZ VPS
# surport: Cenost,Fedora 6.x
# Augest 24, 2014 v1.00
#url:
echo"######################################################"
echo"Interactive PoPToP Install Script for an OpenVZ VPS"
echo
echo"Make sure to contact your provider and have them enable"
echo"IPtables and ppp modules prior to setting up PoPToP."
echo"PPP can also be enabled from SolusVM."
echo
echo"You need to set up the server before creating more users."
echo"A separate user is required per connection or machine."
echo"######################################################"
echo
echo
echo"######################################################"
echo"Select on option:"
echo"1) Set up new PoPToP server AND create one user"
echo"2) Create additional users"
echo"######################################################"
read x
if test$x-eq 1; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
## get the VPS IP
#ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
echo
echo"######################################################"
echo"Downloading and Installing ppp and pptpd"
echo"######################################################"
yum install ppp-y
rpm-Uvh
yum install pptpd-y
echo
echo"######################################################"
echo"Creating Server Config"
echo"######################################################"
cp/etc/ppp/options.pptpd/etc/ppp/options.pptpd.bak
sed-i'70a ms-dns 8.8.8.8'/etc/ppp/options.pptpd
# setting up pptpd.conf
sed-i'101a localip 192.168.9.1'/etc/pptpd.conf
sed-i'102a remoteip 192.168.9.11-30'/etc/pptpd.conf
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Forwarding IPv4 and Enabling it on boot"
echo"######################################################"
cat>>/etc/sysctl.conf<<END
net.ipv4.ip_forward=1
END
sysctl-p
echo
echo"######################################################"
echo"Updating IPtables Routing and Enabling it on boot"
echo"######################################################"
iptables-t nat-A POSTROUTING-o eth0-j MASQUERADE
# saves iptables routing rules and enables them on-boot
iptables-save>/etc/iptables.conf
cat>/etc/network/if-pre-up.d/iptables<<END
#!/bin/sh
iptables-restore</etc/iptables.conf
END
chmod+x/etc/network/if-pre-up.d/iptables
cat>>/etc/ppp/ip-up<<END
ifconfig ppp0 mtu 1400
END
echo
echo"######################################################"
echo"Restarting PoPToP"
echo"######################################################"
sleep 5
/etc/init.d/pptpd restart
echo
echo"######################################################"
echo"Server setup complete!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
# runs this if option 2 is selected
elif test$x-eq 2; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Addtional user added!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
else
echo"Invalid selection, quitting."
exit
fi
复制下面代码到install.sh中,然后 sh isntall.sh。这个是只支持debian和ubuntu系列,centos不支持。
复制代码代码如下:
#!/bin/bash
# Interactive PoPToP install script for an OpenVZ VPS
# Tested on Debian 5, 6, and Ubuntu 11.04
# April 2, 2013 v1.11
#
echo"######################################################"
echo"Interactive PoPToP Install Script for an OpenVZ VPS"
echo
echo"Make sure to contact your provider and have them enable"
echo"IPtables and ppp modules prior to setting up PoPToP."
echo"PPP can also be enabled from SolusVM."
echo
echo"You need to set up the server before creating more users."
echo"A separate user is required per connection or machine."
echo"######################################################"
echo
echo
echo"######################################################"
echo"Select on option:"
echo"1) Set up new PoPToP server AND create one user"
echo"2) Create additional users"
echo"######################################################"
read x
if test$x-eq 1; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# get the VPS IP
ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
echo
echo"######################################################"
echo"Downloading and Installing PoPToP"
echo"######################################################"
apt-get update
apt-get-y install pptpd
echo
echo"######################################################"
echo"Creating Server Config"
echo"######################################################"
cat>/etc/ppp/pptpd-options<<END
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
END
# setting up pptpd.conf
echo"option/etc/ppp/pptpd-options">/etc/pptpd.conf
echo"logwtmp">>/etc/pptpd.conf
echo"localip$ip">>/etc/pptpd.conf
echo"remoteip 10.1.0.1-100">>/etc/pptpd.conf
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Forwarding IPv4 and Enabling it on boot"
echo"######################################################"
cat>>/etc/sysctl.conf<<END
net.ipv4.ip_forward=1
END
sysctl-p
echo
echo"######################################################"
echo"Updating IPtables Routing and Enabling it on boot"
echo"######################################################"
iptables-t nat-A POSTROUTING-j SNAT--to$ip
# saves iptables routing rules and enables them on-boot
iptables-save>/etc/iptables.conf
cat>/etc/network/if-pre-up.d/iptables<<END
#!/bin/sh
iptables-restore</etc/iptables.conf
END
chmod+x/etc/network/if-pre-up.d/iptables
cat>>/etc/ppp/ip-up<<END
ifconfig ppp0 mtu 1400
END
echo
echo"######################################################"
echo"Restarting PoPToP"
echo"######################################################"
sleep 5
/etc/init.d/pptpd restart
echo
echo"######################################################"
echo"Server setup complete!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
# runs this if option 2 is selected
elif test$x-eq 2; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# get the VPS IP
ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Addtional user added!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
else
echo"Invalid selection, quitting."
exit
fi
#!/bin/bash
# Interactive PoPToP install script for an OpenVZ VPS
# Tested on Debian 5, 6, and Ubuntu 11.04
# April 2, 2013 v1.11
#
echo"######################################################"
echo"Interactive PoPToP Install Script for an OpenVZ VPS"
echo
echo"Make sure to contact your provider and have them enable"
echo"IPtables and ppp modules prior to setting up PoPToP."
echo"PPP can also be enabled from SolusVM."
echo
echo"You need to set up the server before creating more users."
echo"A separate user is required per connection or machine."
echo"######################################################"
echo
echo
echo"######################################################"
echo"Select on option:"
echo"1) Set up new PoPToP server AND create one user"
echo"2) Create additional users"
echo"######################################################"
read x
if test$x-eq 1; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# get the VPS IP
ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
echo
echo"######################################################"
echo"Downloading and Installing PoPToP"
echo"######################################################"
apt-get update
apt-get-y install pptpd
echo
echo"######################################################"
echo"Creating Server Config"
echo"######################################################"
cat>/etc/ppp/pptpd-options<<END
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 8.8.4.4
proxyarp
nodefaultroute
lock
nobsdcomp
END
# setting up pptpd.conf
echo"option/etc/ppp/pptpd-options">/etc/pptpd.conf
echo"logwtmp">>/etc/pptpd.conf
echo"localip$ip">>/etc/pptpd.conf
echo"remoteip 10.1.0.1-100">>/etc/pptpd.conf
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Forwarding IPv4 and Enabling it on boot"
echo"######################################################"
cat>>/etc/sysctl.conf<<END
net.ipv4.ip_forward=1
END
sysctl-p
echo
echo"######################################################"
echo"Updating IPtables Routing and Enabling it on boot"
echo"######################################################"
iptables-t nat-A POSTROUTING-j SNAT--to$ip
# saves iptables routing rules and enables them on-boot
iptables-save>/etc/iptables.conf
cat>/etc/network/if-pre-up.d/iptables<<END
#!/bin/sh
iptables-restore</etc/iptables.conf
END
chmod+x/etc/network/if-pre-up.d/iptables
cat>>/etc/ppp/ip-up<<END
ifconfig ppp0 mtu 1400
END
echo
echo"######################################################"
echo"Restarting PoPToP"
echo"######################################################"
sleep 5
/etc/init.d/pptpd restart
echo
echo"######################################################"
echo"Server setup complete!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
# runs this if option 2 is selected
elif test$x-eq 2; then
echo"Enter username that you want to create(eg. client1 or john):"
read u
echo"Specify password that you want the server to use:"
read p
# get the VPS IP
ip=`ifconfig venet0:0| grep'inet addr'| awk{'print$2'}| sed s/.*://`
# adding new user
echo"$u*$p*">>/etc/ppp/chap-secrets
echo
echo"######################################################"
echo"Addtional user added!"
echo"Connect to your VPS at$ip with these credentials:"
echo"Username:$u##### Password:$p"
echo"######################################################"
else
echo"Invalid selection, quitting."
exit
fi
如何在CenTos 7上开启关闭防火墙
CentOS 7.0默认配置中采用了firewall作为防火墙系统,而iptables则需要重新设定。如果您想要直接关闭firewall,可以使用以下命令:
首先,使用systemctl命令停止firewall服务:systemctl stop firewalld.service
接着,使用同样的命令禁用firewall的开机启动:systemctl disable firewalld.service
如果需要通过iptables进行防火墙设置,可以通过以下步骤安装相关服务:
运行以下命令安装iptables-services:service yum-y install iptables-services
若要调整防火墙的配置,比如增加3306端口,可以使用vi编辑器打开iptables配置文件:vi/etc/sysconfig/iptables
在文件末尾添加规则如下:-A INPUT-m state--state NEW-m tcp-p tcp--dport 3306-j ACCEPT
完成编辑后保存并退出vi编辑器,然后重启iptables服务以使更改生效:systemctl restart iptables.service
最后,设置iptables开机启动:systemctl enable iptables.service
完成以上步骤后,重启系统以确保所有设置生效。