LoginSignup
34
50

More than 1 year has passed since last update.

VyOS

Last updated at Posted at 2020-03-09

VyOS検証

昨今クラウドの台頭からかソフトウェアルータであるVyOSの利用用途が増えてきている。
VyOSはLinuxベースのソフトウェアルータだが、ネットワークルーティング、ファイアウォール、Webプロキシ、VPNまでハードウェアルータが持っている機能を数多く再現可能。今回はNWの勉強がてら、VyOSの使い方をまとめたいと思う。

参考
https://wiki.vyos-users.jp/index.php/%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E3%82%AC%E3%82%A4%E3%83%89

1.初期システム設定

VyOSではシステムの各設定をする際にvyosユーザで以下特別なコマンドで実施する。
OSの基本的な設定を行う。

設定系コマンド
#バージョン表示
show system image

#設定モード
config (configure)

# メモリ上でSAVE
commit

#次回OS起動時でも反映されるようにディスクにSAVE
save

#通常モードへ戻る
exit

### 以下を設定モード中に実行して具体的な詳細設定を行う
# 設定実施
set XXX

# 設定削除
delete XXX

# 設定参照
show XXX

NIC

set interfaces ethernet eth0 address 192.168.56.222/24
set interfaces ethernet eth1 address 192.168.1.222/24

VLAN Sub-Interfaces (802.1Q)

set interfaces ethernet eth0 vif 100 description 'VLAN 100'
set interfaces ethernet eth0 vif 100 address '192.168.100.1/24'
set interfaces ethernet eth0 vif 100 address '192.168.200.1/24'

※この例では 100 がVLAN ID.

IPv6無効化

set system ipv6 disable

Default Gateway

### v1.1以前
set system gateway-address '192.168.1.1'

### v1.2以降
set protocols static route 0.0.0.0/0 next-hop '192.168.1.1'

Host Name

set system host-name vyos1

Timezone

set system time-zone 'Asia/Tokyo'

User/Password

set system login user vyos authentication plaintext-password vyos
set system login user root authentication plaintext-password vyos
set system login user testuser1 authentication plaintext-password P#ssw0rd

SSH

set service ssh
set service ssh port 22

DNS

これでVyOS自体が名前解決可能になる

set system name-server '8.8.8.8'
set system domain-search domain 'example.com'

DNS Forwarding

これで他のサーバがVyOSをDNSサーバに指定することで名前解決可能になる

set service dns forwarding cache-size '0'
set service dns forwarding listen-on 'eth0'
set service dns forwarding name-server '8.8.8.8'

NTP

#NTP サーバ設定
set system ntp server 'ntp.nict.jp'

#NTP サーバ同期状態確認
show ntp

シスログ

# Linuxで言う所の/var/log/messages
show log

# シスログをtail
show log tail

SSH 公開鍵登録

set system login user vyos authentication public-keys identifier key "AAAAB3Nz...."
set system login user vyos authentication public-keys identifier type ssh-rsa"

静的ホストマッピング

set system static-host-mapping host-name [ホスト名] inet [IPアドレス]

初期セットアップ

configure
set system host-name vyos1
set system time-zone 'Asia/Tokyo'
set system ipv6 disable
set system login user vyos authentication plaintext-password vyos
set system login user root authentication plaintext-password vyos
set system name-server '8.8.8.8'
set system domain-search domain 'example.com'
set system ntp server 'ntp.nict.jp'
commit
save
exit

2.NAT

Source NAT

これでVyOS配下のサーバがLAN外部と通信可能

set nat source rule 10 outbound-interface eth0
set nat source rule 10 source address 0.0.0.0/0
set nat source rule 10 translation address masquerade

Destination NAT

以下では、ルータ自身:80に届いた通信を192.168.56.30:80に変換して対象サーバへ転送する。

set nat destination rule 10 destination port 80
set nat destination rule 10 inbound-interface eth1
set nat destination rule 10 protocol tcp
set nat destination rule 10 translation address 192.168.56.30

NAT ステータス確認

NAT 機能では新たな通信が開始されるたびにセッションテーブルにアドレス変換エントリが作成され、以降の通信はこのテーブルを参照してアドレス変換、パケット転送を行う。

show nat source translations detail

3.ルーティング

静的ルーティング

静的ルーティング
set protocols static route <宛先NWアドレス/サブネットマスク> next-hop <経由ルータ>


set protocols static route 192.168.198.0/24 next-hop 192.168.1.30
set protocols static route 192.168.176.0/24 next-hop 192.168.1.40
※疎通先同士で両方設定しないとPINGがお互い通らない

例えばvyos2のeth1のNW情報をvyos1がripで知るためには、
vyos1とvyos2をつなぐNIC(eth0)に対して以下でripプロトコルを有効化。
加えてvyos2でNIC(eth1)に対してripプロトコルを有効化する必要がある。

動的ルーティング(RIP)

#隣のHopのルーターへ配布する経路情報を含むIFを指定
set protocols rip interface eth0
set protocols rip interface eth1
set protocols rip interface eth2
set protocols rip interface eth3

#経路交換しないIFを指定(隣のHopにルーターが不在)
set protocols rip passive-interface eth0
set protocols rip passive-interface eth1

#明示的に直接接続するIFの経路情報を配布
set protocols rip redistribute connected
動的ルーティング(OSPF)
※ルータごとにrouter-idは一意に分割する
VyOS#1
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.1
set protocols ospf area 0.0.0.0 network 192.168.198.0/24
set protocols ospf area 0.0.0.0 network 192.168.176.0/24
set protocols ospf redistribute connected
commit
save

VyOS#2
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.2
set protocols ospf area 0.0.0.0 network 192.168.198.0/24
set protocols ospf area 0.0.0.0 network 192.168.216.0/24
set protocols ospf area 0.0.0.0 network 192.168.156.0/24
set protocols ospf redistribute connected
commit
save

動的ルーティング(BGP)

以下のような 3 つのAS間での BGP ルーティングを実現する。

image.png

# ノード1
configure
delete protocols bgp
set protocols bgp 64496 network '1.1.1.0/24'
set protocols bgp 64496 parameters router-id '1.1.1.1'

set protocols bgp 64496 neighbor 192.168.0.2 peer-group AS64497
set protocols bgp 64496 peer-group AS64497 remote-as 64497
set protocols bgp 64496 peer-group AS64497 soft-reconfiguration inbound

set protocols bgp 64496 neighbor 192.168.0.3 peer-group AS64498
set protocols bgp 64496 peer-group AS64498 remote-as 64498
set protocols bgp 64496 peer-group AS64498 soft-reconfiguration inbound

commit
save

# ノード2
configure
delete protocols bgp
set protocols bgp 64497 network '2.2.2.0/24'
set protocols bgp 64497 parameters router-id '2.2.2.2'

set protocols bgp 64497 neighbor 192.168.0.1 peer-group AS64496
set protocols bgp 64497 peer-group AS64496 remote-as 64496
set protocols bgp 64497 peer-group AS64496 soft-reconfiguration inbound

set protocols bgp 64497 neighbor 192.168.0.3 peer-group AS64498
set protocols bgp 64497 peer-group AS64498 remote-as 64498
set protocols bgp 64497 peer-group AS64498 soft-reconfiguration inbound

commit
save

# ノード3
configure
delete protocols bgp
set protocols bgp 64498 network '3.3.3.0/24'
set protocols bgp 64498 parameters router-id '3.3.3.3'

set protocols bgp 64498 neighbor 192.168.0.1 peer-group AS64496
set protocols bgp 64498 peer-group AS64496 remote-as 64496
set protocols bgp 64498 peer-group AS64496 soft-reconfiguration inbound

set protocols bgp 64498 neighbor 192.168.0.2 peer-group AS64497
set protocols bgp 64498 peer-group AS64497 remote-as 64497
set protocols bgp 64498 peer-group AS64497 soft-reconfiguration inbound

commit
save

# BGP 状態確認 @ VyOS-1
show ip bgp
<---------------------------------------------------------
BGP table version is 0, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       0.0.0.0                  1         32768 i
*  2.2.2.0/24       192.168.0.2                            0 64498 64497 i
*>                  192.168.0.2              1             0 64497 i
*  3.3.3.0/24       192.168.0.3                            0 64497 64498 i
*>                  192.168.0.3              1             0 64498 i

Total number of prefixes 3
--------------------------------------------------------->

show ip bgp summary
<---------------------------------------------------------
BGP router identifier 1.1.1.1, local AS number 64496
IPv4 Unicast - max multipaths: ebgp 1 ibgp 1
RIB entries 5, using 480 bytes of memory
Peers 2, using 9120 bytes of memory
Peer groups 2, using 64 bytes of memory

Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
192.168.0.2     4 64497      14      17        0    0    0 00:11:58        2
192.168.0.3     4 64498       5       7        0    0    0 00:02:28        2

Total number of neighbors 2
--------------------------------------------------------->

AS-PATH-PREPEND

set policy route-map RM-Router rule 10 action permit
set policy route-map RM-Router rule 10 set as-path-prepend "64999 64999"
set protocols bgp 65002 neighbor <ネイバーのIP> address-family ipv4-unicast route-map export 'RM-Router'

4.Firewall

VyOS ではファイアウォール細かい粒度のファイアウォールを設定することができる。VyOS のファイアウォールは内部的にはLinuxのnetfilterを使っている。
基本的には、ファイアウォールのルールを作成し、当該ルールをインターフェースに割り当てるとイメージで適用が可能。

ここで重要な概念としてOSの各インターフェースに割り当てる際に指定する「IN・OUT・LOCAL」というルールの適用形式があるので説明したい。

こちらの参考資料によると以下のような定義。加えて補足説明したい。
https://support.rackspace.com/how-to/configuring-interface-based-firewall-on-the-vyatta-network-appliance/

  • In
    If you apply the instance as in, the firewall filters packets that enter the interface and traverse the Vyatta system. You can apply one in packet filter.
    => 要するにIptables のFORWARDチェインのINに該当する定義。
    VyOS自体への通信ではなくほかのサーバにルーティングするような通信の場合に、実際にパケットが入ってくるインターフェイスに割り当てることで通信を制御する。

  • Out
    If you apply the instance as out, the firewall filters packets that leave the interface. These can be packets that traverse the Vyatta system or that originated on the system. You can apply one out packet filter.
    => 要するにIptables のFORWARDチェインのOUTに該当する定義。
    VyOS自体への通信ではなくほかのサーバにルーティングするような通信の場合に、実際にパケットが出ていくインターフェイスに割り当てることで通信を制御する。

  • Local
    If you apply the instance as local, the firewall filters packets that are destined for the Vyatta system. One firewall instance can be applied as a local packet filter.
    => 要するにIptables のINPUTチェインに該当する定義。
    VyOS自体への通信で実際にパケットが入ってくるインターフェイスに割り当てることで通信を制御する。INやOUTとは異なり、ルーターとしてのルーティング処理に適用される訳ではなく、ルーター自身を宛先にしたパケットを制御する。

Vyatta主要コマンド

https://wiki.vyos.net/wiki/User_Guide
http://akkkix.hatenablog.com/entry/2017/01/27/185318
https://blog.sotm.jp/2014/10/13/Installing-OSS-Router-VyOS-Vyatta/
https://beginners-network.com/rip.html
https://qiita.com/vivi_dokou/items/8517542d4e8eb0ad2c97

VyOSでAWSリージョン間VPN
https://dev.classmethod.jp/cloud/aws/vyos-aws-vpn/

VyOSで自宅とAWSのVPN
http://raptor-falcon.hatenablog.com/entry/2017/09/27/064309

#静的経路設定
set protocols static route 192.168.198.0/24 next-hop 192.168.1.30
set protocols static route 192.168.176.0/24 next-hop 192.168.1.40
※疎通先同士でしかないとPINGがお互い通らない

vyos1
delete protocols static
set protocols static route 192.168.216.102/32 next-hop 192.168.198.32
set protocols static route 192.168.216.103/32 next-hop 192.168.176.33
set protocols static route 192.168.164.0/24 next-hop 192.168.198.32
set protocols static route 192.168.215.0/24 next-hop 192.168.176.33

vyos2
delete protocols static
set protocols static route 192.168.164.104/32 next-hop 192.168.156.34
set protocols static route 192.168.215.105/32 next-hop 192.168.216.33
set protocols static route 192.168.216.103/32 next-hop 192.168.216.33

vyos3
delete protocols static
set protocols static route 192.168.164.104/32 next-hop 192.168.216.32
set protocols static route 192.168.215.105/32 next-hop 192.168.215.35
set protocols static route 192.168.216.102/32 next-hop 192.168.216.32


#Source NAT変換(静的) これでインターネットと通信は可能
set nat source rule 1 source address 0.0.0.0/0
set nat source rule 1 translation address 192.168.1.31
set nat source rule 1 outbound-interface eth0

(説明)
1行目
NATによって変換する送信元IPアドレスを「0.0.0.0/0」に指定しています。「0.0.0.0/0」はすべてのIPアドレスが対象になります。したがって、この場合は、送信元IPアドレスに関わらず全てのトラフィックが変換対象となります。ちなみに、「rule」の後に続く数字の「1」は、任意の番号です。

2行目
1行目で指定した送信元IPアドレスを「192.168.1.30」に変換しています。

3行目
1行目、2行目で変換したトラフィックが出て行くインターフェースを「eth0」に指定しています。

#Destination NAT変換(eth0から192.168.64.150にアクセスしてきたら172.16.0.10に送る)
set nat destination rule 1 destination address 192.168.1.31
set nat destination rule 1 destination port 80
set nat destination rule 1 inbound-interface eth0
set nat destination rule 1 protocol tcp
set nat destination rule 1 translation address 192.168.1.101

##RIP
例えばvyos2のeth1のNW情報をvyos1がripで知るためには、
vyos1とvyos2をつなぐNICに対して以下でripプロトコルを有効化。
加えてvyos2でNIC(eth1)に対してripプロトコルを有効化する必要がある。

・VyOS#1
delete protocols static
delete protocols rip
delete protocols ospf
set protocols rip interface eth0
set protocols rip interface eth1
set protocols rip interface eth2
set protocols rip passive-interface eth0
commit
save

・VyOS#2/#3
delete protocols static
delete protocols rip
delete protocols ospf
set protocols rip interface eth0
set protocols rip interface eth1
set protocols rip interface eth2
commit
save

・VyOS#4
delete protocols static
delete protocols rip
delete protocols ospf
set protocols rip interface eth0
set protocols rip interface eth1
set protocols rip interface eth2
set protocols rip passive-interface eth1 
set protocols rip passive-interface eth2
commit
save


##OSPF
※ルータごとにrouter-idは一意に分割する
・VyOS#1
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.1
set protocols ospf area 0.0.0.0 network 192.168.198.0/24
set protocols ospf area 0.0.0.0 network 192.168.176.0/24
set protocols ospf redistribute connected
commit
save

・VyOS#2
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.2
set protocols ospf area 0.0.0.0 network 192.168.198.0/24
set protocols ospf area 0.0.0.0 network 192.168.216.0/24
set protocols ospf area 0.0.0.0 network 192.168.156.0/24
set protocols ospf redistribute connected
commit
save

・VyOS#3
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.3
set protocols ospf area 0.0.0.0 network 192.168.176.0/24
set protocols ospf area 0.0.0.0 network 192.168.216.0/24
set protocols ospf area 0.0.0.0 network 192.168.215.0/24
set protocols ospf redistribute connected
commit
save

・VyOS#4
delete protocols static
delete protocols rip
delete protocols ospf
set protocols ospf parameters router-id 127.0.0.4
set protocols ospf area 0.0.0.0 network 192.168.156.0/24
set protocols ospf area 0.0.0.0 network 192.168.164.0/24
set protocols ospf area 0.0.0.0 network 192.168.90.0/24
set protocols ospf redistribute connected
commit
save



##DHCP
set service dhcp-server disabled 'false'
set service dhcp-server shared-network-name eth1 subnet 192.168.216.0/24
set service dhcp-server shared-network-name eth1 subnet 192.168.216.0/24 start 192.168.216.210 stop 192.168.216.240
set service dhcp-server shared-network-name eth1 subnet 192.168.216.0/24 default-router '192.168.216.33'
set service dhcp-server shared-network-name eth1 subnet 192.168.216.0/24 lease '86400'


## VRRP
・VyOS#1
------------------------------
# eth0側の設定
# アドバタイズの間隔を1秒間毎に設定
set interfaces ethernet eth0 vrrp vrrp-group 10 advertise-interval 1
# VIPを192.168.33.31に設定
set interfaces ethernet eth0 vrrp vrrp-group 10 virtual-address 192.168.33.31/24
# 自動フェイルバックをONにする
set interfaces ethernet eth0 vrrp vrrp-group 10 preempt true
# eth0とeth1を連動して切り替えるための設定
set interfaces ethernet eth0 vrrp vrrp-group 10 sync-group syncgrp01
# Masterになる優先度を150に設定 (大きいほど優先される)
set interfaces ethernet eth0 vrrp vrrp-group 10 priority 150
# eth1側の設定
# アドバタイズの間隔を1秒間毎に設定
set interfaces ethernet eth1 vrrp vrrp-group 10 advertise-interval 1
# VIPを192.168.11.31に設定
set interfaces ethernet eth1 vrrp vrrp-group 10 virtual-address 192.168.11.31/24
# 自動フェイルバックをONにする
set interfaces ethernet eth1 vrrp vrrp-group 10 preempt true
# eth0とeth1を連動して切り替えるための設定
set interfaces ethernet eth1 vrrp vrrp-group 10 sync-group syncgrp01
# Masterになる優先度を100に設定 (大きいほど優先される)
set interfaces ethernet eth1 vrrp vrrp-group 10 priority 150
------------------------------

・VyOS#2
------------------------------
# eth0側の設定
# アドバタイズの間隔を1秒間毎に設定
set interfaces ethernet eth0 vrrp vrrp-group 10 advertise-interval 1
# VIPを192.168.33.31に設定
set interfaces ethernet eth0 vrrp vrrp-group 10 virtual-address 192.168.33.31/24
# 自動フェイルバックをONにする
set interfaces ethernet eth0 vrrp vrrp-group 10 preempt true
# eth0とeth1を連動して切り替えるための設定
set interfaces ethernet eth0 vrrp vrrp-group 10 sync-group syncgrp01
# Masterになる優先度を150に設定 (大きいほど優先される)
set interfaces ethernet eth0 vrrp vrrp-group 10 priority 100
# eth1側の設定
# アドバタイズの間隔を1秒間毎に設定
set interfaces ethernet eth1 vrrp vrrp-group 10 advertise-interval 1
# VIPを192.168.11.31に設定
set interfaces ethernet eth1 vrrp vrrp-group 10 virtual-address 192.168.11.31/24
# 自動フェイルバックをONにする
set interfaces ethernet eth1 vrrp vrrp-group 10 preempt true
# eth0とeth1を連動して切り替えるための設定
set interfaces ethernet eth1 vrrp vrrp-group 10 sync-group syncgrp01
# Masterになる優先度を100に設定 (大きいほど優先される)
set interfaces ethernet eth1 vrrp vrrp-group 10 priority 100
------------------------------

#firewall
set firewall name OUTSIDE-IN default-action drop
set firewall name OUTSIDE-IN rule 10 action accept
set firewall name OUTSIDE-IN rule 10 state established enable
set firewall name OUTSIDE-IN rule 10 state related enable
set firewall name OUTSIDE-IN rule 20 action accept
set firewall name OUTSIDE-IN rule 20 protocol tcp
set firewall name OUTSIDE-IN rule 20 source address 192.168.215.105
set firewall name OUTSIDE-IN rule 20 destination port 22,80
set firewall name OUTSIDE-IN rule 30 action accept
set firewall name OUTSIDE-IN rule 30 protocol icmp
set firewall name OUTSIDE-IN rule 30 icmp type-name any
set firewall name OUTSIDE-LOCAL default-action accept
set interfaces ethernet eth0 firewall in name OUTSIDE-IN
set interfaces ethernet eth0 firewall local name OUTSIDE-LOCAL

##VLAN
delete interfaces ethernet eth1 
set interfaces ethernet eth1 vif 200 address 192.168.216.32/24
set interfaces ethernet eth1 vif 200 address 192.168.216.33/24

#DNS Forwarding
set service dns forwarding name-server 8.8.8.8
set service dns forwarding name-server 8.8.4.4
set service dns forwarding cache-size 0
set service dns forwarding listen-on eth1

#VPN(vyattaとの拠点間接続用)設定 Vyatta
・NAT トラバーサルを有効
set vpn ipsec ipsec-interfaces interface eth0
set vpn ipsec nat-traversal enable
set vpn ipsec nat-networks allowed-network 0.0.0.0/0

・IKE と ESP の設定
グループ名以外の設定は、ピアリングする両者で一致していなければいけません。
set vpn ipsec ike-group IKE-1  
set vpn ipsec ike-group IKE-1  proposal 1 encryption aes256 
set vpn ipsec ike-group IKE-1  proposal 1 hash sha1
set vpn ipsec ike-group IKE-1  proposal 2 encryption aes256
set vpn ipsec ike-group IKE-1  proposal 2 hash sha1
set vpn ipsec ike-group IKE-1  lifetime 3600

set vpn ipsec esp-group ESP-1 
set vpn ipsec esp-group ESP-1 proposal 1 encryption aes256 
set vpn ipsec esp-group ESP-1 proposal 1 hash sha1
set vpn ipsec esp-group ESP-1 proposal 2 encryption aes256
set vpn ipsec esp-group ESP-1 proposal 2 hash sha1 
set vpn ipsec esp-group ESP-1 lifetime 3600

・ピアリングの設定
Vyos1
set vpn ipsec site-to-site peer 0.0.0.0
set vpn ipsec site-to-site peer 0.0.0.0 authentication mode pre-shared-secret 
set vpn ipsec site-to-site peer 0.0.0.0 authentication pre-shared-secret PRE_SHARED_SECRET
set vpn ipsec site-to-site peer 0.0.0.0 default-esp-group ESP-1
set vpn ipsec site-to-site peer 0.0.0.0 ike-group IKE-1
set vpn ipsec site-to-site peer 0.0.0.0 local-address 192.168.198.31
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 local prefix 192.168.1.0/24
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 remote prefix 192.168.90.0/24

vyos2
set vpn ipsec site-to-site peer 0.0.0.0
set vpn ipsec site-to-site peer 0.0.0.0 authentication mode pre-shared-secret 
set vpn ipsec site-to-site peer 0.0.0.0 authentication pre-shared-secret PRE_SHARED_SECRET
set vpn ipsec site-to-site peer 0.0.0.0 default-esp-group ESP-1
set vpn ipsec site-to-site peer 0.0.0.0 ike-group IKE-1
set vpn ipsec site-to-site peer 0.0.0.0 local-address 192.168.156.34
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 local prefix 192.168.90.0/24
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 remote prefix 192.168.1.0/24

参考
https://qiita.com/xecus/items/bd843a40ad0b9d9b3d06

5.ブリッジ接続

ローカルブリッジ構築

  • eth0~eth3に接続された同一LAN内のホスト間は通信可能
set interfaces bridge br0
set interfaces bridge br0 address 192.168.1.100/24
set interfaces ethernet eth0 bridge-group bridge br0
set interfaces ethernet eth1 bridge-group bridge br0
set interfaces ethernet eth2 bridge-group bridge br0
set interfaces ethernet eth3 bridge-group bridge br0

6.リンクローカルアドレス

固定のIPアドレスもDHCPからの自動IPアドレス取得もできない時に、169.254.0.0/16のアドレス範囲から自動で対象のネットワークインターフェイスへ払い出されるIPアドレスのこと。技術的には、APIPA(Automatic Private IP Addressing) と呼ぶ。
https://ja.wikipedia.org/wiki/APIPA

一見、用途がよくわからないが、小規模なネットワークではわざわざ固定IPを割り当てたりDHCPを用意するよりこれで済ましてしまった方が楽だったりする。
また、クラウドだとインスタンスメタデータサービス用に169.254.169.254が利用されていたりするし、クラスター製品等で複数ノード間通信のために割り当てられたり(例:Oracle RAC)することもある。当該セグメントのIPを消費しないのでIPの節約にはなりそう。

リンクローカルアドレスは、本来割り当てられるはずのセグメント帯と同一の範囲のサーバーであれば疎通が可能。(ルーターを超えて別のセグメントと疎通することは不可)
同一セグメント帯のリンクローカルアドレス帯同士や、リンクローカルアドレスと当該セグメントIPアドレス間であれば疎通可能。適切にOS上等でルーティングが定義されている必要はある。

Linux のネットワークインターフェイスにリンクローカルアドレスを設定するには以下のような設定で可能。BOOTPROTO=autoip が重要

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=autoip
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=enp0sx
DEVICE=enp0sx
ONBOOT=yes
ETHTOOL_OPTS="autoneg on"
34
50
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
34
50