Linux ifconfig to view ip

Time:2022-9-22

ifconfig

ifconfig is used to display or configure network devices.

  • Set the status and information of network devices
  • Display settings for network devices

grammar

ifconfig [network device][down up -allmulti -arp -promisc][add][del][][io_addr][irq][media][mem_start][metric][mtu][netmask][tunnel][-broadcast ][-pointopoint][IP address]

Common parameters

  • -interface: The specified network interface name, such as eth0 and eth1
  • up: activate the specified network interface card
  • down: shuts down the specified network interface
  • broadcast address: set the broadcast address of the interface
  • pointopoint: enable point-to-point mode
  • address: Set the IP address of the specified interface device
  • netmask address: Set the subnet mask of the interface

More parameter reference

case

View the information of all network cards (including the network cards in the down state)

ifconfig -a
# eth0: NIC name
# Link encap: The interface type of the network card, here is Ethernet
# HWaddr: The hardware address of the network card, commonly known as the MAC address
# inet addr: IPv4 address, if it is IPv6, it will be written as inet6 addr
# Bcast: broadcast address
# Mask: Subnet mask
# UP: Indicates that the network card is on
# BROADCAST: Indicates that the network card supports broadcasting
# RUNNING: Indicates that the network cable of the network card has been connected
# MULTICAST: Indicates that the network card supports multicast
# MTU: network maximum transmission unit
# Metric: The metric of reaching the gateway, reference: http://m.chinabyte.com/network/191/12287691_gfh.shtml
# RX packets: The size of the data packets received by the network since the start of the network, the unit is bytes, the data packets with error occurred, and the dropped data packets
# TX packets: The size of the data packets sent by the network since the start of the network, the unit is bytes, the data packets with error occurred, the dropped data packets
# collisions: collided packets, if it happens too many times, it means that the network condition is not very good
# txqueuelen: the storage length of the buffer for transferring data
# RX bytes: total amount of bytes received
# TX bytes: total amount of bytes sent
# Memory: The memory address of the network card hardware

Display network device information (active)

ifconfig

Start and shut down the specified network card

ifconfig eth0 up
ifconfig eth0 down

Configure IP address

ifconfig eth0 192.168.120.56 
ifconfig eth0 192.168.120.56 netmask 255.255.255.0 
ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255

ifconfig eth0 192.168.120.56

Configure the IP address for the eth0 network card: 192.168.120.56

ifconfig eth0 192.168.120.56 netmask 255.255.255.0

Configure the IP address for the eth0 network card: 192.168.120.56 and add the submask: 255.255.255.0

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255

Configure the IP address for the eth0 network card: 192.168.120.56, add the submask: 255.255.255.0, and add a broadcast address: 192.168.120.255

Recommended Today

Laohuangli fortune-telling interface implementation and code example

The old almanac fortune-telling interface provides the old almanac query, and the almanac daily fortune-telling and taboo query. Interface name: Laohuangli fortune-telling interface Interface Platform: Aggregate Data (http://www.juhe.cn) interface address:http://v.juhe.cn/laohuangli/d Supported formats: JSON/XML Request method: HTTP GET/POST Request example:http://v.juhe.cn/laohuangli/d… Example of JSON return of the old yellow calendar fortune-telling interface: { “reason”: “successed”, “result”: { […]