Вот решение для Ubuntu 18.04 со сценарием if -up и брандмауэром -cmd инструментом(nmcli not' почему-то не работает)
Станьте пользователем root и создайте файл if -up с правами администратора
sudo su -
touch /etc/network/if-up.d/p2p1-trusted && chmod +x $_
Поместите следующий контент и сохраните файл
#!/bin/sh
# check if script is executed for the interface we need
if [ "$IFACE" != "p2p1" ]; then
exit 0
fi
firewall-cmd --zone=trusted --change-interface="$IFACE"
Перезагрузка
Подтвердить
$ sudo firewall-cmd --get-active-zones
trusted
interfaces: p2p1
public
interfaces: wlp1s0
#!/bin/bash
URL="https://www.gitignore.io/api/nonexistentlanguage"
response=$(curl -s -w "%{http_code}" $URL)
http_code=$(tail -n1 <<< "$response") # get the last line
content=$(sed '$ d' <<< "$response") # get all but the last line which contains the status code
echo "$http_code"
echo "$content"
(Существуют и другие способы, такие как --write-out
во временный файл. Но в моем примере не нужно прикасаться к диску, чтобы записать какой-нибудь временный файл и не забыть его удалить; все делается в оперативной памяти)
Использование --записи -и временного файла привело меня к:
url="https://www.gitignore.io/api/$1"
tempfile=$(mktemp)
code=$(curl -s $url --write-out '%{http_code}' -o $tempfile)
if [[ $code != 200 ]] ; then
echo "$url SAID $code"
rm -f $tempfile
return $code
fi
mv $tempfile $target