Search
Duplicate
📒

[Linux CLI] 05-2 네트워크 명령어 - curl, ping , ip, ss

상태
수정중
수업
Linux
주제
4 more properties
참고

네트워크 명령어

curl(Client url)

NOTE
여러 프로토콜을 이용하여 네트워크 명령을 전송하는 도구이다!
# curl [option ..] <url> curl http://info.cern.ch/ # URL HTML dmdekq curl https://jsonplaceholder.typicode.com/posts # URL 응답 게시물 curl https://www.google.com/images/branding/googlelogo/1x/google_color_272x92dp.png # 파일 다운로드 curl -O http://example.com/file1.txt googleRobots.txt # O(파일이름 저장) curl -O http://example.com/file1.txt -O http://example.com/file2.txt # 다중파일 저장 curl -o googleRobots.txt http://www.google.com/robots.txt curl -sO [파일이름] [경로] # -s 옵션 사용하면 전송 속도와 같은 부가 정보 안나타남 curl -I http://example.com # I(HTTP 헤더정보 가져오기) curl -x http://proxyserver:port http://example.com # -x(프록시 통한 요청) curl -u username:password http://example.com # -u (사용자 인증) curl -d "param1=value1&param2=value2" -X POST http://example.com/resource # X(HTTP 메소드) curl -H "X-Header: Value" http://example.com # H(헤더 추가요청 보내기)
Bash
복사
HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TELNET.. 등지원되는 프로토콜중 하나를 골라 서버간 데이터 전송할 수 있음
프록시 지원, 사용자 인증, FTP 업로드, 등 유용한 기능을 제공한다.

기타 사용방법

# 이 명령을 사용하면 curl은 기본적으로 # HTTP 프로토콜을 사용하여 google.com에 접속하려고 시도합니다. # 즉, 기본적으로 http://google.com에 접속하려고 시도하는 것입니다. # HTTP는 암호화되지 않은 통신 방식입니다. # 하지만 google.com은 https를 사용해야하므로 자동으로 리다이렉트됨! curl google.com # => 301 리다이렉트 나옴 # 이 명령은 HTTPS 프로토콜을 사용하여 google.com에 접속하려고 시도합니다. # HTTPS는 SSL/TLS를 사용하여 암호화된 통신을 제공합니다. curl https://google.com # 홈페이지 나옴
Bash
복사
curl google.com vs curl https://google.com

telnet(Teletype Network)

NOTE
네트워크 호스트와 포트에 연결이 가능한지 확인할 수 있는 기본 명령어다!
# telnet <hostname or IP> <port> telnet 13.209.3.36 22 telnet example.com 80
Bash
복사

ping

NOTE
네트워크 호스트와 포트에 연결이 가능한지 확인할 수 있는 기본 명령어다!
ping example.com ping -c 4 example.com # c(카운트 4번) ping -w 10 example.com # w(제한시간 10초) ping -s 120 exmple.com # s(패킷크기) ping -f example.com # f(매우 빠르게많이 보내기) ping -a example.com # a(알람, 도달하면 소리) ping -I eth0 example.com # I(네트워크 인터페이스 지정) ping -o example.com # o(한번 성공하면 멈춤)
Bash
복사

wget(컨텐츠 다운로드)

NOTE
웹 서버에서 컨텐츠를 다운로드 하기 위한 명령어다!
# wget [option]... [URL]... wget https://example.com/file.zip wget -b https://example.com/largefile.zip # -b(백그라운드) wget --limit-rate=200k https://example.com/file.zip # --limit-reate(200k) wget -i urls.txt # i(여러 파일 다운로드) wget --mirror https://example.com # --mirror(웹사이트 전체 다운로드) wget -O myFile.zip https://example.com/file.zip # 다른 이름으로 저장 wget -P /path/to/direcotry https://example.com/file.zip # 특정 디렉토리에 저장
Bash
복사

ip(ifonfig 대처 명령어)

NOTE
ip명령어는 리눅스에서 네트워크 인터페이스, IP 주소, 라우팅 테이블 등을 관리하는데 사용된다!
ip link show # 모든 네트워크 인터페이스 조회 ip link set dev eth0 up/down # eth0 활성화/비활성화 ip -c address # c(color 알록달록) ip addr show # 모든 네트워크 인터페이스에 할당된 IP주소 확인 ip addr add 192.168.1.10/24 eth0 # 인터페이스에서 IP추가 ip addr del 192.168.1.10/24 eth0 # 인터페이스에서 IP제거 ip route # 라우트 테이블 표시 ip route add 192.168.1.0/24 via 192.168.1.1 # 라우트 추가 ip route del 192.168.1.0/24 # 라우트 제거 # 외부/공용 IP주소를 확인하는 방법 (외부 IP => 인터넷에 연결된 장치에 의해 사용되는 주소) # ex) WI-FI의 경우 공유기가 사용하는 주소 curl ifconfig.me curl ifconfig.co hostname # host 이름 hostname -i # host ip주소 ip netns list # 시스템에 존재하는 모든 네트워크 네임스페이스 나열 ip nets add/del [네임스페이스 이름] # 네임스페이스 생성/삭제 ip netns exec [네임스페이스 이름] ip addr # 해당 네임스페이스에서 명령어 실행
Bash
복사

ss(socket 상태조회, netstat 대처)

NOTE
# ss (netstat 명령어 대체) ss # listening socket 제외한 모든소켓 ss -tulnp # l(listening), t(tcp), u(udp), n(numeric value), -p(process) ss -tulnp | grep :80 # 특정 포트 (예: 80)를 사용하는 연결 확인 (sport => source port) ss -tulnp | grep -i scheduler # 스케쥴러 컴포넌트 확인 ss -a # 모든 소켓 ss -f unix -f netlink # f(FAMILAY(unix, inet, link ..), 소켓유형) ss -t4 # IPv4 ss -t6 # IPv6 #netplan get # ip설정을 영구저장하기 위함 #sudo netplan try --timeout 60 #sudo netplan apply #resolvectl status #sudo vi /etc/systemd/resolved.conf # DNS 수정 #sudo systemctl restart systemd-resolved.service # 재시작 #resolvectl dns # dns 확인
Bash
복사

dig(DNS)

NOTE
DNS를 질의할 수 있는 도구이다!
dig example.com # 도메인 IP조회 dig example.com +short # 짧게보기 curl -H "Host: example.com" http://93.184.216.34 # 실제 IP조회후 테스트(Host를 해줘야 제대로감) dig @8.8.8.8 example.com # 특정 도메인 지정 dig ns exmpale.com # example.com의 네임서버 조회
Bash
복사