一、查看
命令:ifconfig
结果如下
~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.153.125 netmask 255.255.255.0 broadcast 192.168.153.255
ether 00:0c:29:10:bb:2b txqueuelen 1000 (以太网)
RX packets 6916 bytes 2844196 (2.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5034 bytes 936442 (936.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 374 bytes 27084 (27.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 374 bytes 27084 (27.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
其中inet 为ip,netmask为子网掩码,broadcast为 广播地址
二、修改
1.修改ip地址:sudo ifconfig eth0 192.168.153.126
注(重要):修改完后会出现断网问题,用netstat -rn查看网关时发现网关丢失。解决办法:手动添加网关:sudo route add default gw 192.168.153.2
2.修改子网掩码:ifconfig eth0 192.168.120.56 netmask 255.255.255.0
注意:同上。
3.修改广播地址:ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
注意:同上。