Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/sh
  2.  
  3. ####################################
  4. #                                  #
  5. # host -> gateway -> INTERNET      #
  6. #                                  #
  7. ####################################
  8.  
  9. # Ethernet card in host computer
  10. ECARDINHOST=eth0
  11. # Ethernet card in gateway computer (connects to host)
  12. ECARTINGW_2HOST=eth0
  13. # Ethernet card in gateway computer (connects to Internet)
  14. ECARDINGW_2INTERNET=eth1
  15.  
  16.  
  17. ## Settings for host<->gateway network
  18.  
  19. # Netmask
  20. NETMASK=255.255.255.0
  21. # IP address for gateway
  22. IP_GW=192.168.50.2
  23. # IP address for host
  24. IP_HOST=192.168.50.1
  25.  
  26.  
  27. if [ "$#" -eq "0" ]; then
  28.     echo -e "Usage:\n\t$0 [--gateway|--host]\n"
  29.     exit 0
  30. elif [ "$#" -eq "1" ]; then
  31.     case "$1" in
  32.         "--gateway")
  33.             #checking internet connection
  34.             ping -W 5 -c 1 ya.ru
  35.             if [ "$?" -ne "0" ]; then
  36.                 echo 'No Internet connection! Aborting!!!'
  37.                 exit 1
  38.             fi
  39.             # enable packet forwarding
  40.             sudo -u root -s "echo 1 > /proc/sys/net/ipv4/ip_forward"
  41.             sudo ifconfig $ECARTINGW_2HOST $IP_GW netmask $NETMASK
  42.             sudo iptables -t nat -A POSTROUTING -o $ECARDINGW_2INTERNET -j MASQUERADE
  43.             echo 'Add this lines to /etc/resolv.conf in host computer (not in gateway!):'
  44.             echo
  45.             cat /etc/resolv.conf
  46.             echo
  47.             exit 0
  48.             ;;
  49.         "--host")
  50.             sudo ifconfig $ECARDINHOST $IP_HOST netmask $NETMASK
  51.             sudo route add default gw $IP_GW
  52.             echo 'Add lines from gateway resolv.com to host resolv.conf'
  53.             echo 'Do not forget say "sudo route del default gw 192.168.50.2"!'
  54.             exit 0
  55.             ;;
  56.     esac
  57. fi