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:~#
版权声明: 本文为独家原创稿件,版权归 乐数软件 ,未经许可不得转载。