1
0

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 3 years have passed since last update.

CentOS7で静的ルーティング設定を入れる

Last updated at Posted at 2021-06-28

はじめに

静的ルーティング設定をいれるにあたって
ドハマリしたのでいろいろと調べた結果を整理する

やったこと

・ルーティング追加/削除(ip route add/del)
・ルーティング追加/削除(route-enp0s8)

ルーティング追加/削除(ip route add/del)

一時的なルーティング追加であればこのやりかたが一番簡単
https://www.steponboard.net/centos-7/1098/
より

お手本
# 追加するとき
ip route add 192.168.1.0/24 via 172.16.1.254 dev eth1
# 削除するとき
ip route del 192.168.1.0/24
実際のコマンド
# 追加するとき
ip route add 192.168.33.10/32 via 192.168.33.11 dev enp0s8
# 削除するとき
ip route del 192.168.33.10/32

ルーティングの結果の確認は

ip route show

結果がこちら。
192.168.33.10 via 192.168.33.11 dev enp0s8 が追加されていることがわかる。
image.png

では、ルーティング削除する。

image.png

ルーティング追加/削除(route-enp0s8)

恒久的に追加する方法がコチラ。

  1. インターフェース毎ルーティング設定ファイルを作成して、ルーティング設定を追加する
  2. ネットワークを再起動する

インターフェース毎の設定ファイル置き場は
/etc/sysconfig/network-scripts
のroute-[インタフェース名]になる。
↓↓の例の場合だと、enp0s8なので、、、route-enp0s8になる
初期状態だと、route-…はないので新規で作ってやる必要がある。
image.png

で、以下の要領で設定する

route-enp0s8
192.168.33.10 via 192.168.33.11 dev enp0s8

作った後のファイルの様子はこんな感じ
image.pngimage.png

仕上げにネットワークの再起動。

systemctl restart network

でOK。ただし、、、ここでroute-enp0s8の内容が文法エラーもしくはルーティング設定エラーがおきてる場合、
network.serviceの起動に失敗するので気を付けて!!

ちなみに、↑↑の設定で失敗した場合、enp0s3は↑↑の設定と関係なかったので無事だったけど
enp0s8は設定にかかわっていたので接続が切れてしまった。。。

設定が成功するとこんな感じ。
image.png

ルーティングの削除方法はもっと簡単。
route-enp0s8のルーティング設定を#でコメントアウトすればOK。
結果がコチラ。

image.png

おわりに

インタフェースに対してのIP追加であれば
nmcli down enp0s8;nmcli up enp0s8
でいいけど、ルーティングの場合はネットワーク設定全体に影響するので
ネットワークサービス自体は再起動してやるのでちょっとやり方が変わってくることがよくわかりました。

~おしまい~

1
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?