0
0

More than 1 year has passed since last update.

AWSへのアクセスだけ特別なルーティングをしたい

Posted at

下記URLからjson形式でIPアドレスのリストが取れるそうです。
https://ip-ranges.amazonaws.com/ip-ranges.json

なので、これをルーティングテーブルとして設定するプログラムを書きました。

routing.rb
require 'open-uri'
require 'json'
pp = URI.open('https://ip-ranges.amazonaws.com/ip-ranges.json') {|f| JSON.parse(f.read) }
pp['prefixes'].select{ |p| p['region'] == 'ap-northeast-1' }
              .map { |p| p['ip_prefix'] }
              .each { |ip| system "ip route add #{ip} via 192.168.1.254 dev eth0" }

この手のプログラムを簡単に直感的に書けるところがrubyの良いところですよね。

0
0
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
0