Network.sh 696 B

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