RockyOS 9 여러 인터페이스에 아이피 할당

RockyOS9 은 조금 변경 사항이 있다.

기존 /etc/sysconfig/network-scripts/ 에서 네트워크 설정을 변경 할 수 있었는데.
이제는 /etc/NetworkManager/system-connections 에 저장이 된다.

 

nmcli connection migrate

 

을 사용 하거나

 

nmcli connection migrate <profile_name|UUID|D-Bus_path>

 

을 사용하여 migration 할 수 있다.

 

자세한 내용은 다음과 같다.

더보기

NetworkManager stores new network profiles in keyfile format in the
/etc/NetworkManager/system-connections/ directory.

Previously, NetworkManager stored network profiles in ifcfg format
in this directory (/etc/sysconfig/network-scripts/). However, the ifcfg
format is deprecated. By default, NetworkManager no longer creates
new profiles in this format.

Connection profiles in keyfile format have many benefits. For example,
this format is INI file-based and can easily be parsed and generated.

Each section in NetworkManager keyfiles corresponds to a NetworkManager
setting name as described in the nm-settings(5) and nm-settings-keyfile(5)
man pages. Each key-value-pair in a section is one of the properties
listed in the settings specification of the man page.

If you still use network profiles in ifcfg format, consider migrating
them to keyfile format. To migrate all profiles at once, enter:

# nmcli connection migrate

This command migrates all profiles from ifcfg format to keyfile
format and stores them in /etc/NetworkManager/system-connections/.

Alternatively, to migrate only a specific profile, enter:

# nmcli connection migrate <profile_name|UUID|D-Bus_path>

For further details, see:
* nm-settings-keyfile(5)
* nmcli(1)

 

이렇게 하여 하나의 interface 에 여러 IP 를 할당하는건 비교적 쉽다. nmtui 를 사용하거나 nmcli 를 사용하여 ipv4.addresses 를 ,로 구분하여 지속적으로 추가하면 되지만 여러 interface에 IP 를 할당하여 통신하는건 비교적 어려운 일이다.

 

내 기억으론 centos7 까지는 단순히 다른 대역의 IP 라 하더라도 통신이 잘 할 됐는데 이번에는 문제가 안되는 사항이다.

 

내가 겪은 사항은 다음과 같다.

편의 상 인터페이스 이름과 네트워크 대역은 내 상황에 맞게 작성한다.

 

eth0 : 192.168.0.2/25 gw 192.168.0.1

eth1 : 192.168.1.2/25 gw 192.168.1.2

 

라는 IP를 할당하였을때 당연하겠지만 default gateway 가 가장 먼저 인터페이스가 UP 된 기준으로 하여 통신이 될것이고 192.168.0/25 대역으로만 외부망 통신이 가능할 것이다.

 

내가 원하는 바는 eth0 대역으로 들어온 네트워크는 eth0 으로, eth1 대역으로 들어온 네트워크는 eth1로 통신하고 싶었는데 쉽지 않았다.

 

여러 고민의 결과 끝에 해결 방법을 다음과 같이 찾았다.

 

PBR(Policy-Based Routing) 방식으로 해결했다.

 

1. 각 인터페이스에 사용하고자 하는 네트워크를 설정한다.

 

2.

echo '100 Eth0' >> /etc/iproute2/rt_tables
echo '200 Eth1' >> /etc/iproute2/rt_tables

 

위 명령으로 라우팅 테이블을 작성하기 위한 rule 을 정의 하고

 

3. /etc/NetworkManager/dispatcher.d 로 이동하여 20-pbr 이라는 파일을 생성한다.

4. 생성한 20-pbr 에 다음과 같은 스크립트를 작성한다.

#!/bin/bash
# 인터페이스 이름과 상태를 환경변수에서 가져옵니다.
INTERFACE=$1
STATUS=$2

# NetworkManager에 의해 설정된 인터페이스 이름을 확인합니다.
test -n "$INTERFACE" || exit 0

# run() 함수는 스크립트의 실행 가능 여부를 검사하고 실행합니다.
run() {
    test -x "$1" || exit 0
    "$1" "$INTERFACE" "$STATUS"
}

# 라우팅 규칙을 설정하는 로직입니다.
set_routing_rules() {
    local iface=$1
    local status=$2

    if [ "$iface" == "eth0" ]; then
        # eth0을 위한 라우팅 규칙을 추가합니다.
	ip route add 192.168.0.0/25 dev eth0 table Eth0
	ip route add default via 192.168.0.1 dev eth0 table Eth0
	ip rule add from 192.168.0.0/25 table Eth0
    fi

    if [ "$iface" == "eth1" ]; then
    	# eth1을 위한 라우팅 규칙을 추가합니다.
        ip route add 192.168.1.0/25 dev eth1 table Eth1
        ip route add default via 192.168.1.1 dev eth1 table Eth1
        ip rule add from 192.168.1.0/25 table Eth1
    fi
}

case "$2" in
    "up")
	    set_routing_rules "$INTERFACE"
	    ;;
    "pre-up")
        ;;
    "down")
        ;;
    "pre-down")
        ;;
esac

 

5. 재부팅

 

간략한 개요는 다음과 같다. static 라우팅 테이블을 잡는 것인데. NetworkManager가 라우팅을 설정 하도록 위임 한 것이라고 생각하면 된다.

 

 

'OS > RockyOS' 카테고리의 다른 글

rockyos 이더넷 속도 제한  (0) 2023.11.17
Routing 테이블 설정  (0) 2023.11.17