네트워크 설정 검증은(는) 무엇을 하나요?
변경 윈도우 전 또는 자동화 실행이 프로덕션 장비에 닿기 전에 네트워크 설정을 검토할 때 이 스킬을 사용하세요.
사용 시기
- Cisco IOS 또는 IOS-XE 스타일 스니펫을 배포 전에 검토할 때
- 스크립트나 템플릿에서 생성된 설정을 감사할 때
- 위험한 명령어, 중복 IP 주소, 서브넷 중복을 찾을 때
- ACL, route-map, prefix-list, line 정책이 참조되었으나 정의되지 않은 경우를 확인할 때
- 네트워크 자동화를 위한 경량 사전 점검 스크립트를 구축할 때
작동 방식
설정 검증을 완전한 파서가 아닌 계층적 증거로 취급하세요. 정규 표현식 검사는 사전 점검 경고에 유용하지만, 최종 승인은 여전히 네트워크 엔지니어가 의도, 플랫폼 구문, 롤백 단계를 검토해야 합니다.
다음 순서로 검증하세요:
- 파괴적 명령어
- 자격 증명 및 관리 평면 노출
- 중복 주소 및 서브넷 중복
- ACL, route-map, prefix-list 및 인터페이스에 대한 유령 참조
- NTP, 타임스탬프, 원격 로깅, 배너 등의 운영 위생
위험한 명령어 감지
import re
DANGEROUS_PATTERNS: list[tuple[re.Pattern[str], str]] = [
(re.compile(r"\breload\b", re.I), "재시작으로 인한 다운타임 발생"),
(re.compile(r"\berase\s+(startup|nvram|flash)", re.I), "영구 저장소 삭제"),
(re.compile(r"\bformat\b", re.I), "장치 파일 시스템 포맷"),
(re.compile(r"\bno\s+router\s+(bgp|ospf|eigrp)\b", re.I), "라우팅 프로세스 제거"),
(re.compile(r"\bno\s+interface\s+\S+", re.I), "인터페이스 설정 제거"),
(re.compile(r"\baaa\s+new-model\b", re.I), "인증 동작 변경"),
(re.compile(r"\bcrypto\s+key\s+(zeroize|generate)\b", re.I), "장치 SSH 키 변경"),
]
def find_dangerous_commands(lines: list[str]) -> list[dict[str, str | int]]:
findings = []
for line_number, line in enumerate(lines, start=1):
stripped = line.strip()
for pattern, reason in DANGEROUS_PATTERNS:
if pattern.search(stripped):
findings.append({
"line": line_number,
"command": stripped,
"reason": reason,
})
return findings
중복 IP 및 서브넷 중복
import ipaddress
import re
from collections import Counter
IP_ADDRESS_RE = re.compile(
r"^\s*ip address\s+"
r"(?P<ip>\d{1,3}(?:\.\d{1,3}){3})\s+"
r"(?P<mask>\d{1,3}(?:\.\d{1,3}){3})\b",
re.I | re.M,
)
def extract_interfaces(config: str) -> list[dict[str, str]]:
results = []
current = None
for line in config.splitlines():
if line.startswith("interface "):
current = line.split(maxsplit=1)[1]
continue
match = IP_ADDRESS_RE.match(line)
if current and match:
ip = match.group("ip")
mask = match.group("mask")
network = ipaddress.ip_interface(f"{ip}/{mask}").network
results.append({"interface": current, "ip": ip, "network": str(network)})
return results
def find_duplicate_ips(config: str) -> list[str]:
ips = [entry["ip"] for entry in extract_interfaces(config)]
counts = Counter(ips)
return sorted(ip for ip, count in counts.items() if count > 1)
def find_subnet_overlaps(config: str) -> list[tuple[str, str]]:
networks = [ipaddress.ip_network(entry["network"]) for entry in extract_interfaces(config)]
overlaps = []
for index, left in enumerate(networks):
for right in networks[index + 1:]:
if left.overlaps(right):
overlaps.append((str(left), str(right)))
return overlaps
관리 평면 검사
액세스 클래스 검사가 관련 없는 줄로 확장되지 않도록 VTY 블록을 섹션별로 파싱합니다.
import re
def iter_blocks(config: str, starts_with: str) -> list[str]:
blocks = []
current: list[str] = []
for line in config.splitlines():
if line.startswith(starts_with):
if current:
blocks.append("\n".join(current))
current = [line]
continue
if current:
if line and not line.startswith(" "):
blocks.append("\n".join(current))
current = []
else:
current.append(line)
if current:
blocks.append("\n".join(current))
return blocks
def check_vty_blocks(config: str) -> list[str]:
issues = []
for block in iter_blocks(config, "line vty"):
if re.search(r"transport\s+input\s+.*telnet", block, re.I):
issues.append("VTY가 Telnet을 허용합니다. SSH만 필요합니다.")
if not re.search(r"\baccess-class\s+\S+\s+in\b", block, re.I):
issues.append("VTY 블록에 인바운드 access-class 소스 제한이 없습니다.")
if not re.search(r"\bexec-timeout\s+\d+\s+\d+\b", block, re.I):
issues.append("VTY 블록에 명시적인 exec-timeout이 없습니다.")
return issues
보안 위생 검사
SECURITY_PATTERNS = [
(re.compile(r"\bsnmp-server community\s+(public|private)\b", re.I),
"기본 SNMP 커뮤니티가 설정됨"),
(re.compile(r"\bsnmp-server community\s+\S+", re.I),
"SNMPv2 커뮤니티 문자열이 설정됨. SNMPv3 authPriv를 권장"),
(re.compile(r"\bip ssh version 1\b", re.I),
"SSH 버전 1이 활성화됨"),
(re.compile(r"\benable password\b", re.I),
"enable password가 존재합니다. enable secret을 사용하세요"),
(re.compile(r"\busername\s+\S+\s+password\b", re.I),
"로컬 사용자가 password 대신 secret을 사용하지 않음"),
]
BEST_PRACTICE_PATTERNS = [
(re.compile(r"\bntp server\b", re.I), "NTP 서버"),
(re.compile(r"\bservice timestamps\b", re.I), "로그 타임스탬프"),
(re.compile(r"\blogging\s+\S+", re.I), "로깅 대상 또는 버퍼"),
(re.compile(r"\bsnmp-server group\s+\S+\s+v3\s+priv\b", re.I), "SNMPv3 authPriv 그룹"),
(re.compile(r"\bbanner\s+(login|motd)\b", re.I), "로그인 배너"),
]
def check_security(config: str) -> list[str]:
return [message for pattern, message in SECURITY_PATTERNS if pattern.search(config)]
def check_missing_hygiene(config: str) -> list[str]:
return [
f"누락: {description}"
for pattern, description in BEST_PRACTICE_PATTERNS
if not pattern.search(config)
]
예제
변경 윈도우 사전 점검
- 붙여넣을 정확한 스니펫에 대해 위험 명령어 검사를 실행합니다.
- 전체 후보 설정에 대해 중복 IP 및 서브넷 중복 검사를 실행합니다.
- 참조된 모든 ACL, route-map, prefix-list가 존재하는지 확인합니다.
- 관리 평면 변경 전에 롤백 명령어와 아웃오브밴드 접근을 확인합니다.
자동화 사전 점검
Netmiko, NAPALM, Ansible 또는 벤더 API 자동화가 생성된 설정을 푸시하기 전에 검증을 차단 게이트로 사용하세요. 위험한 명령어와 자격 증명에 대해서는 폐쇄 실패(fail closed) 처리하고, 변경 범위를 벗어난 모범 사례 격차에 대해 경고합니다.
안티 패턴
- 정규 표현식 검증을 장치 파서로 취급하는 행위
- 드라이런 diff 없이 생성된 설정을 적용하는 행위
- SNMPv2 커뮤니티 문자열을 모니터링 요구 사항으로 권장하는 행위
- VTY 블록을 검사할 때 정규식이 의도치 않게 관련 없는 섹션에 걸쳐 확장되는 경우
- 카운터나 로그를 읽지 않고 ACL을 비활성화하여 방화벽 동작을 테스트하는 행위
함께 보기
- 에이전트:
network-config-reviewer - 에이전트:
network-troubleshooter - 스킬:
network-interface-health