constantin-net

netmenu_new_parm

Sep 18th, 2020
1,332
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. [ -z "$1" ] && echo "iface" && exit 0
  4.  
  5. echo -n "Enter new address: "
  6. read new_address
  7. echo -n "Enter new netmask: "
  8. read new_netmask
  9. echo -n "Enter new gateway: "
  10. read new_gateway
  11. echo -n "Enter new DNS1: "
  12. read dns1
  13. echo -n "Enter new DNS2: "
  14. read dns2
  15. sed -i -r "/iface $1/!b;:x;n;s/address.*/address $new_address/;t;/iface/b;bx" /etc/network/interfaces
  16. sed -i -r "/iface $1/!b;:x;n;s/netmask.*/netmask $new_netmask/;t;/iface/b;bx" /etc/network/interfaces
  17. sed -i -r "/iface $1/!b;:x;n;s/gateway.*/gateway $new_gateway/;t;/iface/b;bx" /etc/network/interfaces
  18. #sed -i "/$2 $3/s/^#\+//" ~/interfaces
  19. if [[ -z `cat /etc/network/interfaces | grep $1` ]]; then
  20.   ip addr add $new_address/$new_netmask dev $iface label $iface
  21.   ip route add default via $new_gateway  dev $iface onlink
  22. fi
  23. #temporary dns
  24. if [ "$dns1" ]; then
  25.     echo -e "nameserver $dns1" > /etc/resolv.conf
  26.     if [ "$dns2" ]; then
  27.         echo -e "nameserver $dns2" >> /etc/resolv.conf
  28.     fi
  29.     else echo "" > /etc/resolv.conf
  30. fi
RAW Paste Data