Skip to main content

2 posts tagged with "network"

View All Tags

네트워크 정책을 통한 Google Kubernetes Engine(GKE)에서 송수신 트래픽 제어

· 14 min read

image

Google Kubernetes Engine(GKE)에서는 컨테이너화된 애플리케이션을 보호하기 위해 포드 간 보안 통신을 유지하는 것이 중요합니다. 네트워크 정책은 클러스터 내 트래픽 흐름에 대한 세부적인 제어를 설정하여 이러한 목표를 달성할 수 있는 강력한 도구를 제공합니다.

다음은 GKE에서 네트워크 정책을 사용하여 인그레스 및 이그레스 트래픽을 제어하는 ​​방법을 간략하게 소개합니다.

1. 개념 이해:

  • 수신: 외부 서비스, 클러스터 내의 다른 포드 또는 로드 밸런서를 포함하여 다양한 소스에서 포드로 전달되는 수신 네트워크 트래픽을 나타냅니다.
  • 송신: 일반적으로 데이터베이스, API 또는 컨테이너 레지스트리와 같은 외부 서비스로 향하는 포드에서 발생하는 나가는 네트워크 트래픽을 나타냅니다.

2. 네트워크 정책 구현:

네트워크 정책은 GKE 클러스터 내의 YAML 리소스로 정의됩니다. 그들은 다음을 지정합니다:

  • 대상 포드: 라벨 또는 네임스페이스로 식별되어 정책이 적용되는 포드를 결정합니다.
  • 트래픽 유형: 정책이 수신, 송신 또는 둘 다를 관리하는지 여부입니다.
  • 허용된 트래픽: 대상 Pod와 통신하도록 허용된 소스 또는 대상 Pod, IP 주소 또는 서비스 계정을 지정하여 정의됩니다.

3. 네트워크 정책의 이점:

  • 보안 강화: 네트워크 정책은 무단 트래픽을 제한함으로써 클러스터 내 데이터 침해 및 무단 액세스 위험을 완화합니다.
  • 최소 권한 원칙: 세분화된 액세스 제어를 시행하여 포드가 올바르게 작동하는 데 필요한 네트워크 액세스만 갖도록 보장할 수 있습니다.
  • 향상된 네트워크 가시성: 네트워크 정책은 허용된 통신 경로에 대한 명확한 이해를 제공하여 문제 해결 및 보안 감사를 용이하게 합니다.

본질적으로 네트워크 정책은 GKE 클러스터 내에서 보안 체크포인트 역할을 하여 데이터 흐름을 규제하고 잠재적인 보안 위협으로부터 애플리케이션을 보호합니다.

구현 세부정보

이 개념 증명에서는 네임스페이스 생성에 대한 초기 단계와 해당 네임스페이스 내의 세 가지 배포를 통해 Kubernetes 환경에 대한 구성 및 설정 세부 정보를 간략하게 설명합니다.

1. 네임스페이스 생성:

Kubernetes 클러스터 내의 리소스를 격리하고 구성하기 위해 "sample"이라는 네임스페이스가 생성되었습니다.

2. 배포 개요:

세 개의 배포가 "sample" 네임스페이스 내에 설정되었으며 각각 이름은 다음과 같습니다.

  • "sample-app-1"
  • "sample-app-2"
  • "sample-app-3"

3. 이미지 선택:

배포에서는 컨테이너화를 위해 'gcloud-slim' Docker 이미지를 활용합니다. 이 이미지는 리소스 효율성 및 최적화에 대한 특정 요구 사항을 충족하기 위해 선택되었습니다.

4. YAML 파일:

sample-app-1, 2, 3의 배포 YAML은 아래와 같습니다.

apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app-1
namespace: sample
spec:
replicas: 1
selector:
matchLabels:
app: sample-app-1
template:
metadata:
labels:
app: sample-app-1
spec:
containers:
- image: google/cloud-sdk:slim
name: gcloud-test-app
command: ["sleep", "infinity"]

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app-2
namespace: sample
spec:
replicas: 1
selector:
matchLabels:
app: sample-app-2
template:
metadata:
labels:
app: sample-app-2
spec:
containers:
- image: google/cloud-sdk:slim
name: gcloud-test-app
command: ["sleep", "infinity"]

---

apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app-3
namespace: sample
spec:
replicas: 1
selector:
matchLabels:
app: sample-app-3
template:
metadata:
labels:
app: sample-app-3
spec:
containers:
- image: google/cloud-sdk:slim
name: gcloud-test-app
command: ["sleep", "infinity"]

네트워크 정책은 YAML 매니페스트를 사용하여 설정되었으며 "샘플" 네임스페이스 내에서 통신 권한을 구성합니다. 특히 "sample-app-1"은 "sample-app-2"와, "sample-app-2"는 "sample-app-3"과 양방향으로 통신할 수 있으며 그 반대의 경우도 마찬가지입니다. 그러나 “sample-app-3”에서 “sample-app-1”로의 통신은 정의된 정책에 따라 제한됩니다. 설명된 설정은 제어되고 선택적인 포드 간 통신을 보장합니다.

그래픽적으로 다음과 같이 나타낼 수 있습니다.

그림 1: 기술 아키텍처 | 네트워크 정책의 도식적 표현

image

네트워크 정책 YAML 파일:

우리는 네트워크 정책을 사용하여 시행되는 클러스터 내 트래픽을 제어하기 위해 특정 수신 및 송신 정책을 적용했습니다. 외부 트래픽의 경우 Istio 서비스 항목을 사용하고 있습니다.

수신 허용 트래픽:

  • GCP 외부 HTTPS 부하 분산기 상태 확인 IP 범위는 포트 80,443에서만 130.211.0.0/22, 35.191.0.0/16입니다.
  • 포트 80 및 443에서만 샘플 네임스페이스의 샘플-앱-2 배포에서.
  • 모든 포트의 kube-system 및 istio-system 네임스페이스 배포에서.

송신 허용 트래픽:

  • GCP의 메타데이터 서버 — 포트 988의 169.254.169.252/32 및 포트 80의 169.254.169.254/32
  • 포트 80 및 443의 네임스페이스 샘플에 샘플-앱-2를 배포합니다.
  • 모든 포트의 kube-system 및 istio-system 네임스페이스에 배포됩니다.

그림 2: 기술 아키텍처 | sample-app-1에 대한 네트워크 정책의 그래픽 표현

image

sampl-app-1의 네트워크 정책 yaml은 아래와 같습니다.

## For sample-app1, below network polciy yaml is applied

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: sample-app-1-nw-policy
namespace: sample
spec:
podSelector:
matchLabels:
app: sample-app-1
policyTypes:
- Ingress
- Egress
ingress:
- from:
- podSelector:
matchLabels:
app: sample-app-2
ports:
- port: 80
- port: 443
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
- from:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: istio-system
- from:
- ipBlock:
cidr: 130.211.0.0/22
ports:
- port: 80
- port: 443
- from:
- ipBlock:
cidr: 35.191.0.0/16
ports:
- port: 80
- port: 443
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: istio-system
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
- to:
- podSelector:
matchLabels:
app: sample-app-2
ports:
- port: 80
- port: 443
- to:
- ipBlock:
cidr: 169.254.169.254/32
ports:
- port: 80
- to:
- ipBlock:
cidr: 169.254.169.252/32
ports:
- port: 988

확인

  1. 아래 명령을 사용하여 세 개의 포드 모두에 실행합니다.
kubectl exec -it <pod-name> -n sample -- bash

Sample output:

kubectl get pods -n sample
NAME READY STATUS RESTARTS AGE
sample-app-1-7f4c69bc85-wr5mq 1/1 Running 0 39s
sample-app-2-59dfd44fcd-pwpct 1/1 Running 0 32s
sample-app-3-5c8f7c9d4c-zs2p2 1/1 Running 0 26s

root@ganesh-instance-02:~/policies/sample# kubectl exec -it sample-app-1-7f4c69bc85-wr5mq -n sample -- bash

2. 세 포드 모두에 nginx, 컬, 핑 및 기타 유틸리티를 설치합니다.

apt install dnsutils
apt install net-tools
apt install iputils-ping
apt install nginx
service nginx start

sample output:


root@sample-app-1-7f4c69bc85-wr5mq:/# apt install dnsutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
bind9-dnsutils bind9-host bind9-libs libfstrm0 libicu72 libjemalloc2 libjson-c5 liblmdb0 libmaxminddb0 libprotobuf-c1 libuv1 libxml2
Suggested packages:
mmdb-bin
The following NEW packages will be installed:
bind9-dnsutils bind9-host bind9-libs dnsutils libfstrm0 libicu72 libjemalloc2 libjson-c5 liblmdb0 libmaxminddb0 libprotobuf-c1 libuv1 libxml2
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 13.0 MB of archives.
After this operation, 45.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y


root@sample-app-1-7f4c69bc85-wr5mq:/# apt install net-tools
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 243 kB of archives.
After this operation, 1001 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main amd64 net-tools amd64 2.10-0.1 [243 kB]
Fetched 243 kB in 0s (1259 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package net-tools.
(Reading database ... 61295 files and directories currently installed.)
Preparing to unpack .../net-tools_2.10-0.1_amd64.deb ...
Unpacking net-tools (2.10-0.1) ...
Setting up net-tools (2.10-0.1) ...


root@sample-app-1-7f4c69bc85-wr5mq:/# apt install iputils-ping
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libcap2-bin libpam-cap
The following NEW packages will be installed:
iputils-ping libcap2-bin libpam-cap
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 96.2 kB of archives.
After this operation, 311 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libcap2-bin amd64 1:2.66-4 [34.7 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 iputils-ping amd64 3:20221126-1 [47.1 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 libpam-cap amd64 1:2.66-4 [14.5 kB]
Fetched 96.2 kB in 0s (340 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libcap2-bin.
(Reading database ... 61350 files and directories currently installed.)
Preparing to unpack .../libcap2-bin_1%3a2.66-4_amd64.deb ...
Unpacking libcap2-bin (1:2.66-4) ...
Selecting previously unselected package iputils-ping.
Preparing to unpack .../iputils-ping_3%3a20221126-1_amd64.deb ...
Unpacking iputils-ping (3:20221126-1) ...
Selecting previously unselected package libpam-cap:amd64.
Preparing to unpack .../libpam-cap_1%3a2.66-4_amd64.deb ...
Unpacking libpam-cap:amd64 (1:2.66-4) ...
Setting up libcap2-bin (1:2.66-4) ...
Setting up libpam-cap:amd64 (1:2.66-4) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Setting up iputils-ping (3:20221126-1) ...


root@sample-app-1-7f4c69bc85-wr5mq:/# apt install nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
iproute2 libatm1 libbpf1 libelf1 libmnl0 libxtables12 nginx-common
Suggested packages:
iproute2-doc fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
iproute2 libatm1 libbpf1 libelf1 libmnl0 libxtables12 nginx nginx-common
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 2116 kB of archives.
After this operation, 7010 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libelf1 amd64 0.188-2.1 [174 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libbpf1 amd64 1:1.1.0-1 [145 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 libmnl0 amd64 1.0.4-3 [12.5 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 libxtables12 amd64 1.8.9-2 [30.8 kB]
Get:5 http://deb.debian.org/debian bookworm/main amd64 iproute2 amd64 6.1.0-3 [1046 kB]
Get:6 http://deb.debian.org/debian bookworm/main amd64 libatm1 amd64 1:2.5.1-4+b2 [68.3 kB]
Get:7 http://deb.debian.org/debian bookworm/main amd64 nginx-common all 1.22.1-9 [112 kB]
Get:8 http://deb.debian.org/debian bookworm/main amd64 nginx amd64 1.22.1-9 [527 kB]
Fetched 2116 kB in 0s (5728 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libelf1:amd64.
(Reading database ... 61386 files and directories currently installed.)
Preparing to unpack .../0-libelf1_0.188-2.1_amd64.deb ...
Unpacking libelf1:amd64 (0.188-2.1) ...
Selecting previously unselected package libbpf1:amd64.
Preparing to unpack .../1-libbpf1_1%3a1.1.0-1_amd64.deb ...
Unpacking libbpf1:amd64 (1:1.1.0-1) ...
Selecting previously unselected package libmnl0:amd64.
Preparing to unpack .../2-libmnl0_1.0.4-3_amd64.deb ...
Unpacking libmnl0:amd64 (1.0.4-3) ...
Selecting previously unselected package libxtables12:amd64.
Preparing to unpack .../3-libxtables12_1.8.9-2_amd64.deb ...
Unpacking libxtables12:amd64 (1.8.9-2) ...
Selecting previously unselected package iproute2.
Preparing to unpack .../4-iproute2_6.1.0-3_amd64.deb ...
Unpacking iproute2 (6.1.0-3) ...
Selecting previously unselected package libatm1:amd64.
Preparing to unpack .../5-libatm1_1%3a2.5.1-4+b2_amd64.deb ...
Unpacking libatm1:amd64 (1:2.5.1-4+b2) ...
Selecting previously unselected package nginx-common.
Preparing to unpack .../6-nginx-common_1.22.1-9_all.deb ...
Unpacking nginx-common (1.22.1-9) ...
Selecting previously unselected package nginx.
Preparing to unpack .../7-nginx_1.22.1-9_amd64.deb ...
Unpacking nginx (1.22.1-9) ...
Setting up nginx-common (1.22.1-9) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Setting up libatm1:amd64 (1:2.5.1-4+b2) ...
Setting up libmnl0:amd64 (1.0.4-3) ...
Setting up libxtables12:amd64 (1.8.9-2) ...
Setting up libelf1:amd64 (0.188-2.1) ...
Setting up libbpf1:amd64 (1:1.1.0-1) ...
Setting up iproute2 (6.1.0-3) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Setting up nginx (1.22.1-9) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for libc-bin (2.36-9+deb12u4) ...

root@sample-app-2-59dfd44fcd-pwpct:/# service nginx start
Starting nginx: nginx.

3. SSH를 통해 샘플-1 포드의 설정을 확인합니다.

1. curl <sampl-app-2-pod-ip> 80

# Expected Output - nginx welcome page must open

Sample Actual output:
root@ganesh-instance-02:~/policies/sample# kubectl get pods -n sample -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sample-app-1-7f4c69bc85-wr5mq 1/1 Running 0 15m 10.32.0.44 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>
sample-app-2-59dfd44fcd-pwpct 1/1 Running 0 15m 10.32.0.45 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>
sample-app-3-5c8f7c9d4c-zs2p2 1/1 Running 0 15m 10.32.0.46 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>
root@ganesh-instance-02:~/policies/sample# kubectl exec -it sample-app-1-7f4c69bc85-wr5mq -n sample -- bash
root@sample-app-1-7f4c69bc85-wr5mq:/# curl 10.32.0.45 80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>


2. Connect to app-3 from app-1: curl <sampl-app-3-pod-ip> 80

# Expected Output - connection should time out.

Sample Actual output:
root@ganesh-instance-02:~/policies/sample# kubectl get pods -n sample -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sample-app-1-7f4c69bc85-wr5mq 1/1 Running 0 15m 10.32.0.44 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>
sample-app-2-59dfd44fcd-pwpct 1/1 Running 0 15m 10.32.0.45 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>
sample-app-3-5c8f7c9d4c-zs2p2 1/1 Running 0 15m 10.32.0.46 gke-sample-test-nw-poli-e2-node-medium-p-ed273764-51g2 <none> <none>

root@sample-app-1-7f4c69bc85-wr5mq:/# curl 10.32.0.46 80
curl: (28) Failed to connect to 10.32.0.46 port 80 after 131344 ms: Couldn't connect to server


3. Connect to Metadata server:

curl -H "Metadata-Flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email

Expected Output:
# If workload identity is setup, GCP SA must be the output. Else Cluster Service Account must be displayed. Basically, the connection must happen.

Sample Actual Output:

root@sample-app-1-7f4c69bc85-wr5mq:/# curl -H "Metadata-Flavor: Google" http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email
test-demo-410111.svc.id.goog




4. nslookup google.com

Expected output: Must connect to nameserver and display DNS server address which is kubeDNS service IP.

Sample Actual output:

root@sample-app-1-7f4c69bc85-wr5mq:/# nslookup google.com
Server: 10.36.0.10
Address: 10.36.0.10#53

Non-authoritative answer:
Name: google.com
Address: 173.194.206.113
Name: google.com
Address: 173.194.206.101
Name: google.com
Address: 173.194.206.100
Name: google.com
Address: 173.194.206.139
Name: google.com
Address: 173.194.206.102
Name: google.com
Address: 173.194.206.138
Name: google.com
Address: 2607:f8b0:4001:c07::8b
Name: google.com
Address: 2607:f8b0:4001:c07::64
Name: google.com
Address: 2607:f8b0:4001:c07::65
Name: google.com
Address: 2607:f8b0:4001:c07::71

제한 사항

표준 GKE 클러스터에는 다음 요구사항 및 제한사항이 적용됩니다.

  • GKE용 워크로드 아이덴티티 제휴를 사용하여 네트워크 정책을 구현하는 경우 메타데이터 서버로의 이그레스를 허용해야 합니다 .
  • 네트워크 정책 적용을 활성화하면 kube-system 프로세스의 메모리 공간이 약 128MB 증가하고 약 300밀리코어의 CPU가 필요합니다. 즉, 기존 클러스터에 네트워크 정책을 사용 설정하면 예약된 작업 부하를 계속 실행하기 위해 GKE 클러스터에서 클러스터 크기를 늘려야 할 수도 있습니다 .
  • 네트워크 정책 시행을 사용 설정하려면 GKE 노드를 다시 만들어야 합니다. 클러스터에 활성 유지 관리 기간이 있는 경우 다음 유지 관리 기간까지 노드가 자동으로 다시 생성되지 않습니다.
  • 네트워크 정책 시행을 실행하기 위해 GCP에서 권장하는 최소 클러스터 크기는 e2-medium 인스턴스 3개입니다.

리소스 요구 사항이 너무 높기 때문에 노드가 f1-micro 또는 g1-small 인스턴스인 클러스터에는 네트워크 정책이 지원되지 않습니다.

결론

네트워크 정책은 GKE 클러스터 내에서 수신 및 송신 트래픽을 제어하는 ​​강력하고 유연한 접근 방식을 제공합니다. 이러한 정책을 효과적으로 정의하고 활용함으로써 우리는 다음을 달성할 수 있습니다.

  • 보안 강화: 무단 트래픽을 제한함으로써 클러스터 내에서 데이터 침해 및 무단 액세스의 위험을 크게 줄입니다.
  • 향상된 제어 및 규정 준수: 네트워크 통신에 대한 세부적인 제어는 최소 권한 원칙에 부합하며 보안 규정 준수를 용이하게 합니다.
  • 단순화된 네트워크 관리: 네트워크 정책은 허용된 통신 경로에 대한 명확한 가시성을 제공하여 문제 해결을 돕고 보안 감사를 단순화합니다.

네트워크 정책 구현에 능숙해지면 GKE 내에서 컨테이너화된 애플리케이션을 위한 보다 안전하고 잘 정의된 환경을 만들 수 있습니다. 이를 통해 우리는 잠재적인 보안 위험을 완화하면서 자신 있게 애플리케이션을 배포하고 관리할 수 있습니다.

Linux에서 Network 명령어 마스터하기!

· 4 min read

image

Linux에서 네트워크 명령어는 시스템 관리, 네트워크 관리 및 DevOps 영역에서 필수적으로 알아야 합니다. DevOps 전문가, 네트워크 관리자, 시스템 관리자는 물론 초보자도 네트워크를 효과적으로 관리하고 문제를 해결할 수 있도록 지원하는 상위 10개 명령을 살펴봅시다.

1. ping

  • 기능: 네트워크 연결에 대한 테스트로 pingICMP 에코 요청을 지정된 호스트 이름 또는 IP 주소로 보냅니다.
  • 사용법
ping google.com  # Check reachability to Google
ping 192.168.1.10 # Test a specific IP address
  • 결과: 응답 시간(왕복 시간) 및 패킷 손실 통계는 네트워크 연결에 대한 체크에 도움이 됩니다.

2. nslookup

  • 기능: 도메인 이름 뒤에 숨은 ip를 알려줍니다. nslookupDNS 서버에 쿼리하여 호스트 이름(예: google.com)을 해당 IP 주소로 변환합니다.
  • 사용법
nslookup google.com  # Discover the IP address behind Google
  • 출력: 호스트 이름과 연결된 IP 주소가 표시되어 도메인 이름이 물리적 시스템에 매핑되는 방식을 이해하는 데 도움이 됩니다.

3. ifconfig(or ip addr)

  • 기능: 네트워크 인터페이스 세부 정보를 보려면 ifconfig(이전 시스템의 경우) 또는 ip addr(최신 시스템의 경우) 이동 명령을 사용하세요. IP 주소, MAC 주소, 인터페이스 상태 등 네트워크 인터페이스에 대한 정보를 표시합니다.
  • 사용법
ifconfig  # (older systems)
ip addr # (newer systems)
  • 출력: 네트워크 구성 및 문제 해결에 중요한 네트워크 인터페이스 목록 및 관련 세부 정보가 제공됩니다.

4. netstat

  • 기능: netstat 네트워크 활동에 대한 포괄적인 보기를 제공합니다. 활성 연결, 수신 포트 및 트래픽 통계를 표시하여 네트워크 활용도 및 잠재적인 문제에 대한 통찰력을 제공합니다.
  • 사용법
netstat -a  # View all network connections (TCP and UDP)
netstat -ltpn # List listening TCP ports with process IDs and names
  • 결과: 네트워크 연결에 대한 풍부한 정보를 통해 리소스 집약적인 프로세스를 식별하고 연결 문제를 진단할 수 있습니다.

5. traceroute(or tracert)

  • 기능: 네트워크 경로가 흐려지면 traceroute(또는 tracert일부 시스템에서는) 도움을 받습니다. 이는 패킷이 대상에 도달하는 데 걸리는 경로를 추적하여 관련된 네트워크 홉을 드러냅니다.
  • 사용법
traceroute google.com  # Trace the route to Google's servers
  • 출력: 경로를 따라 중간 홉 목록이 표시되어 시스템과 대상 대상 간의 잠재적인 병목 현상이나 연결 문제를 정확히 찾아내는 데 도움이 됩니다.

6. ip

  • 기능: 인터페이스 정보 외에도 ip 주소 할당, 경로 설정, 방화벽 규칙 조작 등 네트워크 구성 관리를 위한 강력한 명령 모음을 제공합니다.
  • 사용법
ip route add default via 192.168.1.1  # Add a default route
ip address add 10.0.0.1/24 dev eth0 # Assign an IP address to an interface
  • 출력: 사용된 특정 명령에 따라 다르지만 ip구성 변경에 대한 실시간 피드백을 제공합니다.

7. tcpdump(or wireshark)

  • 기능: 심층 패킷 검사 tcpdump(또는 그래픽 도구 Wireshark)를 사용하는 것이 좋습니다. 지정된 인터페이스에서 네트워크 트래픽을 캡처하여 개별 패킷을 검사하고 네트워크 프로토콜을 분석할 수 있습니다.
  • 사용법
tcpdump -i eth0  # Capture packets on interface eth0
  • 출력: 캡처된 패킷이 자세한 형식으로 표시되므로 네트워크 동작을 진단하고 보안 위협을 식별할 수 있습니다.

8. ssh

  • 기능: Secure Shell 또는 ssh은 원격 시스템 관리를 위한 도구입니다. 이를 통해 다른 Linux 시스템에 대한 보안 연결을 설정하고 로컬로 로그인한 것처럼 명령을 실행할 수 있습니다.
  • 사용법
ssh user@remote_server_ip  # Connect to a remote server as user
  • 출력: 직접 출력은 없지만 연결에 성공하면 서버 관리를 위한 원격 셸이 부여됩니다.

9. nmap(Network Mapper)

  • 기능: 포괄적인 네트워크 정찰 및 보안 감사를 위한 nmap최고의 기능입니다. 대상 시스템을 검사하여 다음을 식별합니다.
  • 개방형 포트: 이는 통신을 위한 잠재적인 진입점입니다.
  • 해당 포트에서 실행되는 서비스: 포트를 사용하고 있는 애플리케이션이나 프로토콜이 표시됩니다.
  • 운영 체제(OS) 및 장치 유형: nmap응답을 기반으로 대상 시스템의 OS를 식별할 수 있는 경우가 많습니다.
  • 사용법
# Basic scan to identify open ports on a target
nmap scanme.nmap.org
# Scan with additional options:
nmap -sS -T4 scanme.nmap.org # Use SYN scan with faster timing template
nmap -A scanme.nmap.org # Aggressive scan for detailed OS and service detection
  • 결과: 다음을 포함한 풍부한 정보를 제공합니다.
  • 열린 포트 및 관련 서비스 목록입니다.
  • OS 감지 세부정보(성공한 경우)
  • 특정 서비스 또는 프로토콜과 관련된 보안 취약성(고급 사용)

10. iptables/nftables (firewalls)

  • 기능: 네트워크 보안을 위해서는 iptables(레거시) 또는 nftables(최신)과 같은 Linux 방화벽이 필수적입니다. 사전 정의된 규칙에 따라 들어오고 나가는 네트워크 트래픽을 제어하여 무단 액세스로부터 시스템을 보호합니다.
  • 사용법 (iptables example):
iptables -A INPUT -p tcp --dport 22 -j ACCEPT  # Allow incoming SSH connections
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT # Allow outgoing traffic to port 80 (HTTP)
  • 출력: 사용된 특정 명령에 따라 다르지만 방화벽은 규칙 생성 및 상태에 대한 피드백을 제공합니다.

+ curl

  • 기능: 네트워크 진단을 넘어 curl HTTP(S)를 통해 데이터를 전송하는 다목적 도구입니다. 이를 통해 파일을 다운로드하고, 웹 API와 상호 작용하고, 명령줄에서 기본 웹 요청을 수행할 수 있습니다.
  • 사용법
curl https://google.com  # Download the Google homepage
curl -o index.html https://website.com/index.html # Download a specific file
  • 출력: 요청이 실패하면 다운로드한 콘텐츠 또는 오류 메시지를 표시합니다.

위의 상위 10가지 명령을 숙지하면 Linux 네트워킹의 문제를 효과적으로 해결해 자신 있게 네트워크를 관리할 수 있는 준비를 갖추게 됩니다. 전문 지식이 성장함에 따라 더욱 발전된 도구를 탐색하고 네트워크 보안 및 최적화 기술을 더욱 깊이 탐구하며 즐거운 네트워킹을 즐겨보세요!