Linux系统配置固定IP地址、主机名

目录

一、编辑网卡配置文件(/etc/sysconfig/network-scripts/ifcfg-eth0)

二、关闭 NetworkManager 服务,禁止其开机启动

三、 重启 network 服务, 并查看 eth0 网卡情况

四、临时修改主机名(举例:修改主机名为 www)

五、修改主机名永久生效(修改)


一、编辑网卡配置文件(/etc/sysconfig/network-scripts/ifcfg-eth0)

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0                                 # eth0 表示 第一块网卡   
HWADDR=00:0C:29:51:E8:31                    # 网卡的物理地址
TYPE=Ethernet                               # 网络类型
UUID=40fce351-c32b-434d-a0a6-39ba849809f6
ONBOOT=yes                                  # yes 表示 随机启动
NM_CONTROLLED=no                            # 设备eth0是否可以由Network Manager工具图形托管
BOOTPROTO=static                            # 值为 static 表示 静态ip, dhcp 表示 动态ip
IPADDR=192.168.174.151                      # 指定 静态 IP 地址
GATEWAY=192.168.174.1                       # 指定 网关 IP
NETMASK=255.255.255.0                       # 子网掩码 

二、关闭 NetworkManager 服务,禁止其开机启动

[root@localhost ~]# service NetworkManager stop
停止 NetworkManager 守护进程:                             [确定]
[root@localhost ~]# chkconfig NetworkManager off
[root@localhost ~]# chkconfig --list  NetworkManager 
NetworkManager 	0:关闭	1:关闭	2:关闭	3:关闭	4:关闭	5:关闭	6:关闭

三、 重启 network 服务, 并查看 eth0 网卡情况

[root@localhost ~]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: Determining if ip address 192.168.174.151 is already in use for device eth0...
                                                           [确定]
[root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:51:E8:31  
          inet addr:192.168.174.151  Bcast:192.168.174.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe51:e831/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:468 errors:0 dropped:0 overruns:0 frame:0
          TX packets:352 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:45944 (44.8 KiB)  TX bytes:42222 (41.2 KiB)

[root@localhost ~]#

四、临时修改主机名(举例:修改主机名为 www)

[root@localhost ~]# hostname            # 查看修改前的主机名
localhost.localdomain
[root@localhost ~]# hostname www        # 修改主机名
[root@localhost ~]# hostname            # 查看修改后的主机名
www
[root@localhost ~]# 

五、修改主机名永久生效(修改)

[root@localhost ~]# vim /etc/sysconfig/network    # 修改主机名的配置文件
[root@localhost ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=www                                      # 将HOSTNAME 的值设置为新的主机名
[root@localhost ~]# service network restart       # 重启 network 网络服务
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0: Determining if ip address 192.168.174.151 is already in use for device eth0...
                                                           [确定]
[root@localhost ~]# init 6                        # 重启系统后发现 命令提示符主机名为 www

猜你喜欢

转载自blog.csdn.net/u010559460/article/details/87902652
今日推荐