Created
March 3, 2015 22:16
-
-
Save iamfat/7be4a6b96d390cfc0653 to your computer and use it in GitHub Desktop.
内网NAT Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $(id -u) != "0" ]; then | |
printf "Error: You must be root to run this tool!\n" | |
exit 1 | |
fi | |
clear | |
printf " | |
######################################################## | |
# # | |
# This is a Shell-Based tool of making LAN to Internet # | |
# throuth NAT. # | |
# There are 2 parts of the tool. This is for NAT_Node. # | |
# # | |
######################################################## | |
" | |
gw=$(ifconfig eth0|awk -F"[: ]+" '/inet addr/{print $4}'|cut -c1-4).0.1 | |
echo "Please input the alternative gateway ip:" | |
read -p "(Default gateway: $gw):" gw | |
if [ "$gw" = "" ]; then | |
gw=$(ifconfig eth0|awk -F"[: ]+" '/inet addr/{print $4}'|cut -c1-4).0.1 | |
fi | |
get_char() | |
{ | |
SAVEDSTTY=`stty -g` | |
stty -echo | |
stty cbreak | |
dd if=/dev/tty bs=1 count=1 2> /dev/null | |
stty -raw | |
stty echo | |
stty $SAVEDSTTY | |
} | |
echo "" | |
echo "We will change the gateway to $gw !" | |
echo "" | |
echo "Press any key to start..." | |
char=`get_char` | |
echo "" | |
os=$(head -n1 /etc/issue|cut -d\ -f1) | |
case $os in | |
CentOS) | |
sed -i "s/.*GATEWAY.*/GATEWAY=$gw/" /etc/sysconfig/network-scripts/ifcfg-eth0 | |
service network restart | |
;; | |
Ubuntu) | |
sed -i "s/.*gateway.*/gateway $gw/" /etc/network/interfaces | |
/etc/init.d/networking restart | |
;; | |
*) | |
echo "The script does not apply to this operating system." | |
;; | |
esac | |
printf " | |
######################################################## | |
# # | |
# This is a Shell-Based tool of making LAN to Internet # | |
# throuth NAT. # | |
# There are 2 parts of the tool. This is for NAT_Node. # | |
# # | |
######################################################## | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment