Fixed firewalld setting in CentOS 7
This commit is contained in:
parent
b5b43b6934
commit
334d81afde
|
|
@ -164,23 +164,43 @@ function config_shadowsocks(){
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# iptables set
|
# firewall set
|
||||||
function iptables_set(){
|
function firewall_set(){
|
||||||
echo "iptables start setting..."
|
echo "firewall set start..."
|
||||||
/sbin/service iptables status 1>/dev/null 2>&1
|
if centosversion 6; then
|
||||||
if [ $? -eq 0 ]; then
|
/etc/init.d/iptables status > /dev/null 2>&1
|
||||||
/sbin/iptables -L -n | grep '${shadowsocksport}' | grep 'ACCEPT' >/dev/null 2>&1
|
if [ $? -eq 0 ]; then
|
||||||
if [ $? -ne 0 ]; then
|
iptables -L -n | grep '${shadowsocksport}' | grep 'ACCEPT' > /dev/null 2>&1
|
||||||
/sbin/iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksport} -j ACCEPT
|
if [ $? -ne 0 ]; then
|
||||||
/sbin/iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksport} -j ACCEPT
|
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksport} -j ACCEPT
|
||||||
/etc/init.d/iptables save
|
iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksport} -j ACCEPT
|
||||||
/etc/init.d/iptables restart
|
/etc/init.d/iptables save
|
||||||
|
/etc/init.d/iptables restart
|
||||||
|
else
|
||||||
|
echo "port ${shadowsocksport} has been set up."
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "port ${shadowsocksport} has been set up."
|
echo "WARNING: iptables looks like shutdown or not installed, please manually set it if necessary."
|
||||||
|
fi
|
||||||
|
elif centosversion 7; then
|
||||||
|
systemctl status firewalld > /dev/null 2>&1
|
||||||
|
if [ $? -eq 0 ];then
|
||||||
|
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
|
||||||
|
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
|
||||||
|
firewall-cmd --reload
|
||||||
|
else
|
||||||
|
echo "Firewalld looks like not running, try to start..."
|
||||||
|
systemctl start firewalld
|
||||||
|
if [ $? -eq 0 ];then
|
||||||
|
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
|
||||||
|
firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
|
||||||
|
firewall-cmd --reload
|
||||||
|
else
|
||||||
|
echo "WARNING: Try to start firewalld failed. please enable port ${shadowsocksport} manually if necessary."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "iptables looks like shutdown, please manually set it if necessary."
|
|
||||||
fi
|
fi
|
||||||
|
echo "firewall set completed..."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
@ -279,14 +299,12 @@ function install_shadowsocks_libev(){
|
||||||
download_files
|
download_files
|
||||||
config_shadowsocks
|
config_shadowsocks
|
||||||
install
|
install
|
||||||
if centosversion 6; then
|
firewall_set
|
||||||
iptables_set
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Initialization step
|
# Initialization step
|
||||||
action=$1
|
action=$1
|
||||||
[ -z $1 ] && action=install
|
[ -z $1 ] && action=install
|
||||||
case "$action" in
|
case "$action" in
|
||||||
install)
|
install)
|
||||||
install_shadowsocks_libev
|
install_shadowsocks_libev
|
||||||
|
|
@ -298,4 +316,4 @@ uninstall)
|
||||||
echo "Arguments error! [${action} ]"
|
echo "Arguments error! [${action} ]"
|
||||||
echo "Usage: `basename $0` {install|uninstall}"
|
echo "Usage: `basename $0` {install|uninstall}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user