Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. getinfo()
  4. {
  5. read -p "Enter the IP of your router: (looks like 192.168.1.1) " routerip
  6. read -p "Enter the netmask for your network: (looks like 255.255.255.0) " netmask
  7. read -p "Enter the ip address for your server: (looks like 192.168.1.22) " staticip
  8. }
  9.  
  10. writeinterfacefile()
  11. {
  12. cat << EOF > $1
  13. # This file describes the network interfaces available on your system
  14. # and how to activate them. For more information, see interfaces(5).
  15. # The loopback network interface
  16. auto lo
  17. iface lo inet loopback
  18. # The primary network interface
  19. auto eth0
  20. iface eth0 inet dhcp
  21.  
  22. #Your static network configuration
  23. iface eth0 inet static
  24. address $staticip
  25. netmask $netmask
  26. gateway $routerip
  27. EOF
  28. #don't use any space before of after 'EOF' in the previous line
  29.  
  30. echo ""
  31. echo "Your informatons was saved in '$1' file."
  32. echo ""
  33. exit 0
  34. }
  35.  
  36. file="/home/radu/test"
  37. if [ ! -f $file ]; then
  38. echo ""
  39. echo "The file '$file' doesn't exist!"
  40. echo ""
  41. exit 1
  42. fi
  43.  
  44. clear
  45. echo "Let's set up a static ip address for your site"
  46. echo ""
  47.  
  48. getinfo
  49. echo ""
  50. echo "So your settings are:"
  51. echo "Address of your Router is: $routerip"
  52. echo "The Mask for the Network is: $netmask"
  53. echo "Your decided Server IP is: $staticip"
  54. echo ""
  55.  
  56. while true; do
  57. read -p "Are these informations correct? [y/n]: " yn
  58. case $yn in
  59. [Yy]* ) writeinterfacefile $file;;
  60. [Nn]* ) getinfo;;
  61. * ) echo "Pleas enter y or n!";;
  62. esac
  63. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement