Network.sh 737 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. set -e
  3. # Write Netplan
  4. sudo touch /etc/netplan/01-netcfg.yaml
  5. # Changes dhcp from 'yes' to 'no'
  6. # sed -i "s/dhcp4: yes/dhcp4: no/g" /etc/netplan/01-netcfg.yaml
  7. # Ask for input on network configuration
  8. read -p "Enter the static IP of the server in CIDR notation: " staticip
  9. read -p "Enter the IP of your gateway: " gatewayip
  10. read -p "Enter the IP of preferred nameservers (seperated by a coma if more than one): " nameserversip
  11. echo
  12. cat > /etc/netplan/01-netcfg.yaml <<EOF
  13. network:
  14. version: 2
  15. renderer: networkd
  16. ethernets:
  17. ens160
  18. addresses:
  19. - $staticip
  20. gateway4: $gatewayip
  21. nameservers:
  22. addresses: [$nameserversip]
  23. EOF
  24. sudo netplan apply
  25. echo "==========================="
  26. echo