
Python에서 SSH/Telnet protocol을 구현한 것으로 Network 장비를 cli기반으로 접근하여 제어한다.
Paramiko
Rocky Linux에서 IP 설정

nmtui device status


nmcli connect ens192
nmtui
# 확인
ifconfig


dnf install -y python3-pip
# 작업위치 생성
mkdir ~/netmiko && cd ~/netmiko
# 가상환경 생성
python3 -m venv venv
# 가상환경 시작
source venv/bin/activate
# netmiko 설치
pip install netmiko
# 설치된 패키지 확인
pip list | grep netmiko

c3600 라우터와 Cloud를 하나씩 배치한다.
VMnet1을 Add한다.

와이어를 연결시킨다.



# 설정 모드
conf t
# ip 설정 Outside
ip address 172.16.0.171 255.255.0.0
# ip설정 Inside
ip address 192.168.0.1 255.255.255.0
# ping 설정
do ping 172.16.0.17

R1(config-if)#exit
R1(config)#ip domain-name yslee.local
R1(config)#username admin privilege 15 secret cisco
R1(config)#crypto key generate rsa
The name for the keys will be: R1.yslee.local
Choose the size of the key modulus in the range of 360 to 2048 for your
General Purpose Keys. Choosing a key modulus greater than 512 may take
a few minutes.
How many bits in the modulus [512]: 1024
% Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
R1(config)#line vty 0 4
R1(config-line)#login local
R1(config-line)#transport input ssh
R1(config-line)#exit
R1(config)#enable secret cisco
from netmiko import ConnectHandler
c3660_router = {
'device_type': 'cisco_ios',
'host': '172.16.0.171',
'username': 'admin',
'password': 'cisco',
'port': 22,
'secret': 'cisco'
}
try:
with ConnectHandler(**c3660_router) as net_connect:
net_connect.enable()
config_commands =[
'interface FastEthernet0/0',
'description outside'
]
output = net_connect.send_config_set(config_commands)
print(output)
except Exception as e:
print(f"error: {e}")

python3 c3660.py




NAT- PAT 설정을 Netmiko로 구성한다.
VPC와 Rocky가 통신되어야 한다.
Python c3660.py 작성한 것을 좀 수정해본다.
수동으로 interface를 설정할려면 원래는 en > configure terminal로 들어간다. 하지만, 자동화 할떄는 config_commands라는 리스트를 만들어서 작업을 순서대로 넣으면 된다.
config_commands
from netmiko import ConnectHandler
c3660_router = {
'device_type': 'cisco_ios',
'host': '172.16.0.171',
'username': 'admin',
'password': 'cisco',
'port': 22,
'secret': 'cisco'
}
try:
with ConnectHandler(**c3660_router) as net_connect:
net_connect.enable()
# NAT-PAT 설정을 위한 명령어 리스트
config_commands = [
# 1. 내부 인터페이스 설정 (PC1 연결 방향)
'interface FastEthernet0/1', # 그림상 192.168.0.1 쪽 인터페이스
'ip nat inside',
'no shutdown',
# 2. 외부 인터페이스 설정 (Cloud/VMnet1 연결 방향)
'interface FastEthernet0/0', # 그림상 172.16.0.171 쪽 인터페이스
'ip nat outside',
'no shutdown',
# 3. NAT 대상 IP 허용 리스트 (PC1의 대역 192.168.0.0/24)
'access-list 1 permit 192.168.0.0 0.0.0.255',
# 4. PAT(Overload) 설정
'ip nat inside source list 1 interface FastEthernet0/0 overload',
# 5. 라우팅 설정 (외부로 나가는 기본 경로)
# 게이트웨이는 Cloud1(VMnet1)의 실제 게이트웨이 IP(예: 172.16.0.1)여야 합니다.
'ip route 0.0.0.0 0.0.0.0 172.16.0.1'
]
print("NAT-PAT 설정을 전송 중...")
output = net_connect.send_config_set(config_commands)
print(output)
# 설정 저장
net_connect.send_command("write memory")
except Exception as e:
print(f"error: {e}")



