Fixed firewalld setting in CentOS 7
This commit is contained in:
parent
99bc0b915b
commit
472829b33b
102
shadowsocks.sh
102
shadowsocks.sh
|
|
@ -1,29 +1,29 @@
|
||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
|
||||||
export PATH
|
export PATH
|
||||||
#===============================================================================================
|
#=================================================================#
|
||||||
# System Required: CentOS 6,7, Debian, Ubuntu
|
# System Required: CentOS 6+, Debian 7+, Ubuntu 12+ #
|
||||||
# Description: One click Install Shadowsocks-Python server
|
# Description: One click Install Shadowsocks-Python server #
|
||||||
# Author: Teddysun <i@teddysun.com>
|
# Author: Teddysun <i@teddysun.com> #
|
||||||
# Thanks: @clowwindy <https://twitter.com/clowwindy>
|
# Thanks: @clowwindy <https://twitter.com/clowwindy> #
|
||||||
# Intro: https://teddysun.com/342.html
|
# Intro: https://teddysun.com/342.html #
|
||||||
#===============================================================================================
|
#=================================================================#
|
||||||
|
|
||||||
clear
|
clear
|
||||||
echo ""
|
echo
|
||||||
echo "#############################################################"
|
echo "#############################################################"
|
||||||
echo "# One click Install Shadowsocks-Python server #"
|
echo "# One click Install Shadowsocks-Python server #"
|
||||||
echo "# Intro: https://teddysun.com/342.html #"
|
echo "# Intro: https://teddysun.com/342.html #"
|
||||||
echo "# Author: Teddysun <i@teddysun.com> #"
|
echo "# Author: Teddysun <i@teddysun.com> #"
|
||||||
echo "# Thanks: @clowwindy <https://twitter.com/clowwindy> #"
|
echo "# Thanks: @clowwindy <https://twitter.com/clowwindy> #"
|
||||||
echo "#############################################################"
|
echo "#############################################################"
|
||||||
echo ""
|
echo
|
||||||
|
|
||||||
# Make sure only root can run our script
|
# Make sure only root can run our script
|
||||||
function rootness(){
|
function rootness(){
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "Error:This script must be run as root!" 1>&2
|
echo "Error:This script must be run as root!" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,18 +74,18 @@ fi
|
||||||
function pre_install(){
|
function pre_install(){
|
||||||
# Not support CentOS 5
|
# Not support CentOS 5
|
||||||
if centosversion 5; then
|
if centosversion 5; then
|
||||||
echo "Not support CentOS 5.x, please change to CentOS 6,7 or Debian or Ubuntu and try again."
|
echo "Not support CentOS 5, please change to CentOS 6+ or Debian 7+ or Ubuntu 12+ and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Set shadowsocks config password
|
# Set shadowsocks config password
|
||||||
echo "Please input password for shadowsocks-python:"
|
echo "Please input password for shadowsocks-python:"
|
||||||
read -p "(Default password: teddysun.com):" shadowsockspwd
|
read -p "(Default password: teddysun.com):" shadowsockspwd
|
||||||
[ -z "$shadowsockspwd" ] && shadowsockspwd="teddysun.com"
|
[ -z "$shadowsockspwd" ] && shadowsockspwd="teddysun.com"
|
||||||
echo ""
|
echo
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo "password = $shadowsockspwd"
|
echo "password = $shadowsockspwd"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo ""
|
echo
|
||||||
# Set shadowsocks config port
|
# Set shadowsocks config port
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
|
|
@ -95,11 +95,11 @@ function pre_install(){
|
||||||
expr $shadowsocksport + 0 &>/dev/null
|
expr $shadowsocksport + 0 &>/dev/null
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
if [ $shadowsocksport -ge 1 ] && [ $shadowsocksport -le 65535 ]; then
|
if [ $shadowsocksport -ge 1 ] && [ $shadowsocksport -le 65535 ]; then
|
||||||
echo ""
|
echo
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo "port = $shadowsocksport"
|
echo "port = $shadowsocksport"
|
||||||
echo "---------------------------"
|
echo "---------------------------"
|
||||||
echo ""
|
echo
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo "Input error! Please input correct numbers."
|
echo "Input error! Please input correct numbers."
|
||||||
|
|
@ -117,7 +117,7 @@ function pre_install(){
|
||||||
stty echo
|
stty echo
|
||||||
stty $SAVEDSTTY
|
stty $SAVEDSTTY
|
||||||
}
|
}
|
||||||
echo ""
|
echo
|
||||||
echo "Press any key to start...or Press Ctrl+C to cancel"
|
echo "Press any key to start...or Press Ctrl+C to cancel"
|
||||||
char=`get_char`
|
char=`get_char`
|
||||||
#Install necessary dependencies
|
#Install necessary dependencies
|
||||||
|
|
@ -135,7 +135,7 @@ function pre_install(){
|
||||||
IP=$(curl -s -4 ipinfo.io/ip)
|
IP=$(curl -s -4 ipinfo.io/ip)
|
||||||
fi
|
fi
|
||||||
echo -e "Your main public IP is\t\033[32m$IP\033[0m"
|
echo -e "Your main public IP is\t\033[32m$IP\033[0m"
|
||||||
echo ""
|
echo
|
||||||
#Current folder
|
#Current folder
|
||||||
cur_dir=`pwd`
|
cur_dir=`pwd`
|
||||||
cd $cur_dir
|
cd $cur_dir
|
||||||
|
|
@ -173,23 +173,43 @@ function config_shadowsocks(){
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# iptables set
|
# firewall set
|
||||||
function iptables_set(){
|
function firewall_set(){
|
||||||
echo "iptables start setting..."
|
echo "firewall set start..."
|
||||||
/etc/init.d/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 Shadowsocks
|
# Install Shadowsocks
|
||||||
|
|
@ -208,11 +228,9 @@ function install_ss(){
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /usr/bin/pip ]; then
|
if [ -f /usr/bin/pip ]; then
|
||||||
if [ "$OS" == 'CentOS' ]; then
|
if centosversion 6; then
|
||||||
if centosversion 6; then
|
# Fix swig failed error by install old version
|
||||||
# Fix swig failed error by install old version
|
pip install M2Crypto==0.22.3
|
||||||
pip install M2Crypto==0.22.3
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
pip install M2Crypto
|
pip install M2Crypto
|
||||||
fi
|
fi
|
||||||
|
|
@ -226,12 +244,12 @@ function install_ss(){
|
||||||
chkconfig --add shadowsocks
|
chkconfig --add shadowsocks
|
||||||
chkconfig shadowsocks on
|
chkconfig shadowsocks on
|
||||||
else
|
else
|
||||||
update-rc.d shadowsocks defaults
|
update-rc.d -f shadowsocks defaults
|
||||||
fi
|
fi
|
||||||
# Run shadowsocks in the background
|
# Run shadowsocks in the background
|
||||||
/etc/init.d/shadowsocks start
|
/etc/init.d/shadowsocks start
|
||||||
else
|
else
|
||||||
echo ""
|
echo
|
||||||
echo "Shadowsocks install failed! Please visit https://teddysun.com/342.html and contact."
|
echo "Shadowsocks install failed! Please visit https://teddysun.com/342.html and contact."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -300,15 +318,13 @@ function install_shadowsocks(){
|
||||||
config_shadowsocks
|
config_shadowsocks
|
||||||
install_ss
|
install_ss
|
||||||
if [ "$OS" == 'CentOS' ]; then
|
if [ "$OS" == 'CentOS' ]; then
|
||||||
if centosversion 6; then
|
firewall_set
|
||||||
iptables_set
|
|
||||||
fi
|
|
||||||
fi
|
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
|
install_shadowsocks
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user