ip rules (iproute2)

Sabayon, Calculate, Funtoo, Exherbo

Модератор: /dev/random

Аватара пользователя
DaemonTux
Сообщения: 1480
Статус: Юный падаван
ОС: Gentoo

ip rules (iproute2)

Сообщение DaemonTux »

Поскольку стандартные скрипты не умеют работать с ip rules(iproute2)
Решил исправить эту недоработку. И решил выложить то что получилось. Вдруг кому нибудь пригодится. Вот что получилось

Код:

################################## # My code. add and remove ip rules ################################## # get rules from /etc/conf.d/net # #rules_eth1="from 24.80.102.112/32 to 192.168.1.0/24 table localnet priority 100 # from 216.113.223.51/32 to 192.168.1.0/24 table localnet priority 100" # # postup() { # remove old file if exist file="/var/lib/rules_${IFVAR}" if [ -e "$file" ]; then rm $file fi IFS=$'\n' eval set -- \$rules_${IFVAR} if [ $# != 0 ]; then einfo "Adding IP policy routing rules" eindent # Ensure that the kernel supports policy routing if ! ip rule list | grep -q "^"; then eerror "You need to enable IP Policy Routing (CONFIG_IP_MULTIPLE_TABLES)" eerror "in your kernel to use ip rules" else for x; do unset IFS ebegin $x ip rule add $x echo $x >>$file eend $? done fi eoutdent # Flush the cache ip route flush cache dev "${IFACE}" fi unset IFS } postdown() { # Automatically erase any ip rules created in the example postup above if interface_exists "${IFACE}"; then file="/var/lib/rules_${IFVAR}" # Remove any rules for this interface if [ -e "$file" ]; then einfo "Deleting IP policy routing rules" eindent cat $file | while read rule; do ebegin ${rule} ip rule del ${rule} eend $? done if [ -e "$file" ]; then rm $file fi eoutdent fi # # Flush the route cache ip route flush cache dev "${IFACE}" fi # # Return 0 always return 0 }

Этот код помещаем в /etc/init.d/net.lo
Ругайте (:
Vladivostok Linux User Group
Спасибо сказали:
Аватара пользователя
xorader
Сообщения: 1030
Статус: собирающий миры
ОС: Debian

Re: ip rules (iproute2)

Сообщение xorader »

Не читал, но осуждаю
Molchanov Alexander (aka Xor)
*offtopic* - ololo!
Спасибо сказали: