1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
vim gen_ipv6_from_mac.sh ------------------------ #!/bin/bash # vars IFACE=ens5 PREFIX=2001:abc:: PROG_IPV6CALC="/usr/bin/ipv6calc" # Script test prog [[ -e "${PROG_IPV6CALC}" ]] if [[ "$?" != "0" ]]; then echo -e "\n\tPlease install ipv6calc \n\tNot run script, exit. \n "; exit; fi #functions macaddr(){ ip link show | grep -A 1 ${IFACE} | grep ether | awk '{print $2}' } ipgen(){ ipv6calc --in prefix+mac ${PREFIX} "$(macaddr)" 2>/dev/null } ipaddressthen(){ ip -o a | grep ${IFACE} | grep "$(ipgen)" | awk '{print $4}' } badipaddressthen(){ echo "$(ipaddressthen)"|sed 's/\/64//' } # IP_ADDRESS_AND_PREFIX_LIKE="$(ipgen)/64" echo -e " \n\tInterface: \t${IFACE} \n\tPrefix:\t${PREFIX}\n\tIP address generated:\t$(ipgen) \n\tIP address then:\t$(ipaddressthen)\n" # Script add ip if [[ "$(badipaddressthen)" != "$(ipgen)" ]] then ip -6 a a ${IP_ADDRESS_AND_PREFIX_LIKE} dev ${IFACE} echo -e "ADD IP ${IP_ADDRESS_AND_PREFIX_LIKE} dev ${IFACE}" else echo -e "END" exit fi ------------------------ vim /etc/systemd/system/gen_ipv6_from_mac.service -------------------------------------------------- [Unit] Description=gen_ipv6_from_mac.sh [Service] Type=oneshot ExecStart=/usr/bin/gen_ipv6_from_mac.sh Restart=on-failure [Install] WantedBy=multi-user.target -------------------------------------------------- vim /etc/systemd/system/gen_ipv6_from_mac.timer ----------------------------------------------- [Unit] Description=gen_ipv6_from_mac [Timer] OnUnitActiveSec=30 [Install] WantedBy=timers.target ----------------------------------------------- systemctl daemon-reload systemctl enable gen_ipv6_from_mac.service systemctl enable gen_ipv6_from_mac.timer systemctl start gen_ipv6_from_mac.service systemctl start gen_ipv6_from_mac.timer systemctl status gen_ipv6_from_mac.service systemctl status gen_ipv6_from_mac.timer systemctl list-timers systemctl list-timers gen_ipv6_from_mac.timer /etc/systemd/system/gen_ipv6_from_mac.timer каждые 30 сек долбит в скрипт и для ipv6 генерируется адрес (естественно если его еще нет, то генерит, если есть, то не генерит) |