ifconfig 用於查看 管理網絡配置。
OS 可能未集成 ifconfig 命令,使用 apt install net-tools 安裝可獲得。
root:~# ifconfig (或 /sbin/ifconfig)
enp1s0 Link encap:Ethernet HWaddr 00:12:3e:00:13:ec
inet addr:172.00.03.147 Bcast:172.01.09.255 Mask:255.255.200.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:19621631 errors:0 dropped:0 overruns:0 frame:0
TX packets:23356650 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2063380519 (2.0 GB) TX bytes:36088058168 (36.0 GB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
root:~#
基本語法
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [metric <NN>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...
<HW>=Hardware Type,可能的硬件類型:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP) slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP) ash (Ash) ether (Ethernet) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel) ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB) arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device) sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI) irda (IrLAP) ec (Econet) x25 (generic X.25) eui64 (Generic EUI-64)
<AF>=Address family,默認為 inet,可能的地址係列:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE) ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet) ash (Ash) x25 (CCITT X.25)
選項參數
| 參數 | EN 解釋 | 中文翻譯 | 備注 |
|---|---|---|---|
| 功能 | 命令 | 說明 | 備注 |
|---|---|---|---|
| 查看 | ifconfig | 展示網卡信息 | |
| /sbin/ifconfig | |||
| 修改 | ifconfig eth0 192.168.1.71 netmask 255.255.255.0 | 設置 eth0 網卡的當前 IP 地址和子網掩碼 | 重啓計算機後可能失效,推薦 靜態方式 |
| ifconfig enp1s0 192.168.1.71 netmask 255.255.255.0 | 設置 enp1s0 網卡的當前 IP 地址和子網掩碼 | ||
| 版本 | ifconfig -V | 展示版本信息 | |
| ifconfig -version | |||
| 幫助 | ifconfig -h | 展示幫助信息 | |
| ifconfig --help |
以靜態方式配置網卡後,IP 從不改變 (修改前采用 ping 命令,看局域網內是否已存在此 IP):
root:~# vi /etc/network/interfaces (其 enp1s0 為網卡外) # The primary network interface auto enp1s0 iface enp1s0 inet static address 192.168.1.71 gateway 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 root:~# /etc/init.d/networking restart (重啓網絡服務) root:~#
以 DHCP (Dynamic Host Configuration Protocol) 方式配置網卡後,每次啓動時自動從路由器動態獲取 IP 地址:
root:~# vi /etc/network/interfaces (添加 DHCP 行) # The primary network interface - use DHCP to find our address auto enp1s0 iface enp1s0 inet dhcp root:~# /etc/init.d/networking restart (重啓網絡服務或 dhclient enp1s0) root:~#
其它相關技術:
root:~# vi /etc/modprobe.d/blacklist.conf (在文檔最後添加 blacklist ipv6,禁用 IPv6 保存退齣) root:~# cat /etc/modprobe.d/blacklist.conf (查看配置情況) root:~# route add default gw 192.168.2.254 (設置默認網關 192.168.2.254) root:~# vi /etc/resolv.conf (加入 nameserver DNS地址1 和 nameserver DNS地址2,保存退齣) root:~#
版權聲明: 本文為獨傢原創稿件,版權歸 樂數軟件 ,未經許可不得轉載。