Linux下修改主机IP.主机名
1. 修改网络配置
Last login: Sat Sep 6 17:33:02 2014
[root@centos ~]# vi/etc/sysconfig/network-scripts/ifcfg-eth0
--修改前
# Intel Corporation 82540EM GigabitEthernet Controller
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
HWADDR=08:00:27:80:63:5b
~
~
--修改后
# Intel Corporation 82540EM GigabitEthernet Controller
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.53.105.65
NETMASK=255.255.255.0
ONBOOT=yes
HWADDR=08:00:27:80:63:5b
~
[root@centos ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: RTNETLINK answers: Invalid argument
[ OK ]
2. 修改hosts配置
[root@centos ~]# vi /etc/hosts
# Do not remove the following line, orvarious programs
# that require network functionality willfail.
127.0.0.1 centos localhost.localdomainlocalhost
::1 localhost6.localdomain6 localhost6
10.53.105.65 hyldb
~
~
3. 修改network配置
[root@centos ~]# vi /etc/sysconfig/network
--修改前
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=centos
GATEWAY=10.53.105.255
~
~
--修改后
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=hyldb
GATEWAY=10.53.105.255
~
~
--重启系统,使配置生效
[root@centos ~]# reboot
Broadcast message from root (pts/3) (SunSep 7 00:00:08 2014):
The system is going down for reboot NOW!
重启后效果如下:
Last login: Sat Sep 6 23:55:38 2014 from 10.53.105.69
[root@hyldb ~]# ifconfig
eth0 Link encap:Ethernet HWaddr08:00:27:80:63:5B
inet addr:10.53.105.65 Bcast:10.53.105.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe80:635b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5283 (5.1 KiB) TXbytes:10654 (10.4 KiB)
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:5900 errors:0 dropped:0 overruns:0 frame:0
TX packets:5900 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:10634248 (10.1 MiB) TXbytes:10634248 (10.1 MiB)
[root@hyldb ~]# hostname
hyldb
[root@hyldb ~]#