ip 명령어 사용법

|

ip 명령어 사용법

ip 명령어를 이용해서 ip 주소 정보 조회나 ip 설정 등을 할 수 있습니다. ifconfig 명령어와 사용법이 비슷합니다.


사용법

ip [option] [대상] [command]


사용 예제

ip addr show                                            # ip 정보 출력
ip addr add 192.168.5.10/24 dev eth0                    # eth0 인터페이스에 ip 설정
ip addr del 192.168.5.10/24 dev eth0                    # eth0 인터페이스의 ip 삭제
ip link set eth0 up                                     # eth0 인터페이스 활성화
ip link set eth0 down                                   # eth0 인터페이스 비활성화
ip route show                                           # 라우팅 정보 출력
ip route add default via 192.168.5.1                    # 게이트웨이 설정
ip route del default via 192.168.5.1                    # 게이트웨이 삭제
ip route add 10.20.12.0/24 via 192.168.5.1 dev eth0     # 정적 라우팅 정보 설정
ip route del 10.20.12.0/24                              # 정적 라우팅 정보 삭제

netstat 명령어 사용법

|

netstat 명령어 사용법

netstat 명령어를 사용하면 네트워크의 연결 상태 정보를 알 수 있습니다. 네트워크 연결 정보 외에도 라우팅 테이블 정보나 네트워크 인터페이스의 상태, Masqurade 연결 상태 및 멀티캐스트 멤버 정보 등을 조회할 수 있습니다.


사용법

netstat [option] [address_family_option]

옵션은 다음과 같습니다.

  • -a : 모든 소켓 정보 출력
  • -n : 호스트명이나 포트명 대신 숫자로 표시(예를 들어 www는 80으로 출력)
  • -p : 소켓에 대한 PID 및 프로그램명 출력
  • -r : 라우팅 정보 출력
  • -l : Listening(대기)하고 있는 포트 출력
  • -i : 네트워크 인터페이스 테이블 출력
  • -s : 네트워크 통계 정보 출력
  • -c : 네트워크 정보를 주기적으로 계속 출력
  • -t : TCP 기반 접속 목록 출력
  • -u : UDP 기반 접속 목록 출력
  • -g : 멀티캐스트 그룹 정보 출력

address_family_option 항목은 다음과 같은 값을 가질 수 있습니다.

  • –protocol=프로토콜 이름 : inet, unix, ipx, ax25 등 특정 프로토콜 관련 정보 출력
  • –inet, –ip : IP 주소 기반 연결 정보 출력(--protocol=inet과 같은 결과)
  • –unix : Unix Domain Socket 정보 출력(--protocol=unix과 같은 결과)


사용 예제

netstat -anp    # 모든 소켓의 PID 및 프로그램 정보를 출력하고 호스트명이나 포트명은 숫자로 출력
netstat -r      # 라우팅 테이블 정보 출력

route 명령어 사용법

|

route 명령어 사용법

route 명령어는 라우팅 테이블 정보를 조회하거나 관리할 수 있는 명령어입니다.


사용법

route [add|del] [-destination] [netmask] [gateway] [dev interface]

단순히 route 만 실행할 경우에는 기본 라우팅 테이블 정보를 출력하며, netstat -r 명령어와 동일한 기능을 합니다.


사용 예제

route 명령어 사용 예제는 다음과 같습니다. 인터페이스가 하나인 경우는 뒷 부분의 dev eth0는 생략 가능합니다.

route add -net 192.168.5.101 netmask 255.255.255.0 dev eth0     # 네트워트 주소 설정
route del -net 192.168.5.51 netmask 255.255.255.0               # 설정된 네트워크 주소 삭제
route add default gw 192.168.5.1 eth0                           # 게이트웨이 등록
route del default gw 192.168.5.1 eth0                           # 게이트웨이 삭제

ifconfig 명령어 사용법

|

ifconfig 명령어 사용법

ifconfig 명령어는 네트워크 인터페이스 정보를 확인하거나 설정하는 명령어입니다. 사용법은 다음과 같습니다.


사용법

ifconfig [interface name] [address] [option]

예를 들면 etho0 인터페이스를 활성화하거나 비활성화하고 싶으면 다음과 같은 명령어를 내릴 수 있습니다.

ifconfig eth0 up
ifconfig eth down

인터페이스에 ip address를 할당하거나 subnet mask 값이나 broacast 주소 등을 바꾸고 싶은 경우는 다음과 같이 사용합니다.

ifconfig eth0 192.168.0.100 netmask 255.255.255.0 broadcast 192.168.0.255 up

패킷 스니핑(Sniffing)을 하기 위해서는 해당 인터페이스를 promisc 모드로 변경해서 사용할 수 있습니다.

ifconfig eth0 promisc       # promisc 모드 설정
ifconifg eth0 -promisc      # promisc 모드 해제

MAC 주소값을 변경하고 싶은 경우는 다음과 같습니다.

ifconfig eth0 hw ether 00:11:22:33:44:55

키보드를 이용해서 Service Request를 날리고 이벤트를 Subscription하는 예제(Python)

|

키보드를 이용해서 Service Request를 날리고 이벤트를 Subscription하는 예제

import threading
import rclpy, os
import datetime

from tts_service.srv._tts_request import TtsRequest
from tts_service.msg import TtsEvent

NODE_NAME = "tts_service_controller"

client = None;


def callback_on_tts_event_arrived(msg):
    curTime = datetime.datetime.now()
    if msg.event == TtsEvent.EVENT_ON_TTS_STARTED:
        print("[{0}] EVENT_TTS_STARTED".format(curTime))
    elif msg.event == TtsEvent.EVENT_ON_TTS_FINISHED:
        print("[{0}] EVENT_TTS_FINISHED".format(curTime))


def handle_keyboard():
    global client

    while True:
        print("\n")
        print("   1. Request to Speech Text ('Hello')")
        print("   99. Exit")

        menu = input('Input the menu: ')

        if menu == '1':
            req = TtsRequest.Request()
            req.text = "Hello"
            client.call_async(req)

        elif menu == '99':
            rclpy.shutdown()
            os._exit(1)


def main(args=None):
    global client

    rclpy.init(args=args)

    node = rclpy.create_node(NODE_NAME)
    client = node.create_client(TtsRequest, TtsRequest.Request.NAME)
    subscription = node.create_subscription(TtsEvent, TtsEvent.NAME, callback_on_tts_event_arrived)

    th = threading.Thread(target=handle_keyboard)
    th.start()

    try:
        rclpy.spin(node)
    finally:
        node.destroy_node()
        rclpy.shutdown()


if __name__ == '__main__':
    main()
</pre>