Статические маршруты в macos при поднятии VPN

По-умолчанию, при поднятии VPN соединения, Mac OS X пропишет только один статический маршрут, соответствующий создаваемому туннелю. Но бывают ситуации когда необходимо прописать несколько маршрутов для подсетей или хостов. Решить данный вопрос в GUI Mac OS X невозможно. Но возможно через консоль(терминал).

Итак, открываем терминал. Для решения данной задачи создадим файл /etc/ppp/ip-up, и сделаем его исполняемым:

sudo touch /etc/ppp/ip-up
sudo chmod a+x /etc/ppp/ip-up

Открываем созданный файл для редактирования

sudo vim /etc/ppp/ip-up

и пропишем в нем:

#!/bin/sh
ifname=$1        # имя интерфейса pppd (например, ppp3)
ttyname=$2       # имя tty устройства
speed=$3         # скорость tty устройства
localip=$4       # локальный ip адрес
remoteip=$5      # удаленный ip адрес
ipparam=$6       # текущий ip адрес перед установлением VPN соединения

case "$remoteip" in
#IP 1 филиала
    192.168.20.1)
	/sbin/route add -net 192.173.0.0/24 -interface $ifname
        ;;
#IP 2 филиала
    192.168.1.239)
	/sbin/route add -net 192.168.1.0/24 -interface $ifname
        ;;
esac
exit 0;

В данном примере 192.168.20.1 и 192.168.1.239  это ip-адреса VPN-серверов после установления соединения. 192.173.0.0/24 и 192.168.1.0 подсети которые нам необходимо прописать в статичных маршрутах. IP-адрес сервера можно посмотреть после установления VPN соединения командой ifconfig и найти интерфейс ppp0.

ppp0: flags=8051<up,pointopoint,running,multicast> mtu 1448
 inet 192.168.20.57 --> 172.24.48.116 netmask 0xffffff00

Аналогично можно сделать скрипт для удаления маршрутов /etc/ppp/ip-down, который будет вызываться при остановке VPN туннеля:

/sbin/route delete -net 192.0.2.0/24 -interface $ifname
/sbin/route delete -host 192.168.12.54 -interface $ifname

33 комментария к “Статические маршруты в macos при поднятии VPN

  1. Aw, this was a truly wonderful message. In suggestion I would like to place in composing similar to this furthermore? taking time as well as actual initiative to make an excellent write-up? however what can I claim? I procrastinate alot and also by no means appear to get something done.

  2. There are some interesting points in this write-up however I don?t recognize if I see every one of them facility to heart. There is some legitimacy yet I will certainly take hold point of view till I explore it additionally. Great article, thanks and also we want a lot more! Contributed to FeedBurner too

  3. Hello There. I found your blog using msn. This is an extremely well written article.
    I’ll be sure to bookmark it and return to read more of
    your useful info. Thanks for the post. I’ll definitely return. cheap flights 32hvAj4

  4. The following time I review a blog site, I wish that it doesn’t disappoint me as much as this set. I mean, I know it was my selection to review, however I actually assumed youd have something fascinating to state. All I listen to is a number of whimpering about something that you could take care of if you werent as well hectic looking for interest.

  5. Hiya! Quick question that’s totally off topic. Do you know how to make your site mobile friendly?
    My blog looks weird when browsing from my iphone4.

    I’m trying to find a template or plugin that might be able to correct
    this issue. If you have any recommendations, please share.
    Cheers!

  6. Wonderful goods from you, man. I’ve understand your
    stuff previous to and you’re just extremely wonderful.

    I actually like what you’ve acquired here, certainly
    like what you are stating and the way in which you say it. You make it entertaining and you still take
    care of to keep it smart. I can not wait to read far more from you.
    This is actually a great website.

  7. you’re in point of fact a just right webmaster.
    The web site loading speed is incredible. It kind of feels
    that you’re doing any unique trick. In addition, The contents are masterwork.
    you’ve done a excellent task on this matter!

  8. Youre so great! I don’t mean Ive check out anything like this before. So wonderful to discover somebody with some initial thoughts on this subject. realy thanks for starting this up. this website is something that is needed online, a person with a little creativity. useful work for bringing something new to the web!

  9. Can I just say what a relief to locate a person that in fact knows what theyre talking about online. You definitely understand just how to bring a concern to light and also make it vital. More individuals need to read this as well as recognize this side of the tale. I angle think youre not extra preferred because you most definitely have the present.

  10. There are definitely a lot of information like that to take into consideration. That is an excellent point to raise. I use the ideas above as basic motivation however plainly there are concerns like the one you bring up where the most crucial thing will be working in sincere good faith. I don?t understand if best techniques have actually arised around points like that, yet I make certain that your job is clearly recognized as an up for grabs. Both children and also girls feel the influence of simply a moment?s satisfaction, for the remainder of their lives.

  11. This is actually appealing, You’re a significantly seasoned author. I have joined with your feed plus expect witnessing the very good write-ups. And additionally, We’ve shared your web blog inside our social networking sites.

  12. This is the appropriate blog for anyone who wishes to find out about this topic. You realize so much its virtually tough to suggest with you (not that I in fact would want?HaHa). You definitely placed a brand-new spin on a topic thats been covered for years. Great things, simply wonderful!

Оставить ответ

Ваш адрес email не будет опубликован. Обязательные поля помечены *