Linux修改IP地址

  • 小技巧展示:使用nmtui命令可以像在windows下修改ip地址一样,前提是服务器安装了桌面

查看本机IP地址——ifconfig命令:

[root@CactiEZ 1]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:DC:AE:1F  
          inet addr:192.168.1.195  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fedc:ae1f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2358141 errors:0 dropped:0 overruns:0 frame:0
          TX packets:232094 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:330788194 (315.4 MiB)  TX bytes:27939558 (26.6 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:275492 errors:0 dropped:0 overruns:0 frame:0
          TX packets:275492 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:28510647 (27.1 MiB)  TX bytes:28510647 (27.1 MiB)

上面的eth0即是本机网卡名称;ip地址为:192.168.1.195

inet addr:192.168.1.195  Bcast:192.168.1.255  Mask:255.255.255.0

临时修改本机IP地址(也就是说,服务器重启后失效)

注意:修改IP地址过后会断开远程连接,使用时候根据情况而定(下面是常规24为掩码ip地址)

[root@CactiEZ 1]# ifconfig eth0 192.168.1.200/24

注意:如果你是xshell等远程连接的话,现在就会断开连接哦

永久修改本机IP地址:

[root@CactiEZ ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
DNS1="8.8.8.8"
GATEWAY="192.168.1.2"
HOSTNAME="CactiEZ.local"
HWADDR="00:0C:29:DC:AE:1F"
IPADDR="192.168.1.195"
MTU="1500"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"

以上文件在服务器上大多存在,注意修改其中几个,现在将其列在下面:

ONBOOT="yes"
BOOTPROTO="static"
GATEWAY="192.168.1.2"
DNS1="8.8.8.8"
IPADDR="192.168.1.195"
NETMASK="255.255.255.0"

修改完后注意重启network服务,使其生效:

[root@CactiEZ ~]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]

 

你可能感兴趣的:(Linux)