linux - centos7 & ubuntu20 static route add 하기

특정 host 를 목적지로 데이터를 전송할 때 통과하는 gateway를 통과하도록 routing 설정을 할 수 있다.
데이터를 전달 받을 최종 목적지가 10.65.200.90 이라고 하고,
통과해야할 gateway가 27.100.110.40 이라고 하자.

1. centos, ubuntu 공통 : 서버 재시작하면 설정이 사라진다.

route add -host 10.65.200.90 gw 27.100.110.40

2. centos7

network interface를 먼저 확인해야한다.
ifconfig 명령어로 interface list를 확인했을때 데이터를 전송할 interface의 이름이 eno1 이라고 하자.
그렇다면 /etc/sysconfig/network-script/route-eno1 파일을 만들고 그 안에 아래 내용을 저장한다.

10.65.200.90/32 via 27.100.110.40

설정 후 network를 재시작하면 적용된다.

$ sudo systemctl restart network

3. Ubuntu 20.04 server

netplan 설정파일에 적용하면 된다.
/etc/netplan/00-installer-config.yaml 파일에 아래와 같이 해당 interface 하위에 route 내용을 추가한다.

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      addresses:
        - xx.xxx.xxx.xxx/xx
      gateway4: xx.xxx.xxx.xxx
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]
      routes:
        - to: 10.65.200.90
          via: 27.100.110.40

설정 후 netplan 적용 명령어를 실행하면 적용된다.

$ sudo netplan apply

적용내용 확인

route 명령어로 적용 여후 확인한다.

$ route -n

댓글 쓰기

0 댓글