0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MacOS VPN経由を特定のIPアドレスだけにしたいとき

Last updated at Posted at 2023-03-01

VPNをつなぐと基本的にはすべての通信がVPN経由になってしまうので
当方的には、特定のIPへのアクセスのみをVPN経由にしたい

で、いつもどおり調べてみたらVPN接続をすると
/etc/ppp/ip-upシェルスクリプトファイルが呼び出されるんだとか

ということで、VPN先のローカルネットワークと、VPN先からしかIP制限で入れないサーバへのアクセスをppp0経由にすることにしてみた。

sudo vi /etc/ppp/ip-up
/etc/ppp/ip-up
#!/bin/sh

if [ "$1" = "ppp0" ]; then
  date > /tmp/upppp0
  /sbin/route add -net 192.168.xx.0/24 -interface ppp0
  /sbin/route add -net xxx.xxx.xxx.xxx -interface ppp0
fi
sudo chmod 744 /etc/ppp/ip-up

と、設定してVPN接続してみると、date > /tmp/upppp0 が動いて/tmp/upppp0ファイルが作られているので、
if文の中は通っている様子。
(シェルスクリプトなので、こういうデバッグもできるね)

traceroute xxx.xxx.xxx.xxxをしたら、1番目にVPN先のルータのIPになっており、実際にxxx.xxx.xxx.xxxの接続も大丈夫だった。

これで、普段の通信はVPNを経由しなくて済みそうです。

ps.
よくよく考えたら自宅はRTX1200導入してるから、
ルーターでVPNを常に張りっぱなしにして、ルーティング書けは行けそうだなぁ・・
今度余裕があるときやってみよう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?