Set host name
$ sudo hostname server1.example.com
Set resolv.conf
Next we edit /etc/hosts.
Make it look like this:
$ sudo vim /etc/hosts
nameserver 116.228.111.118
nameserver 180.168.255.18
Adjust /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.166 server1 server1.example.com
It is important that you add a line for server1.example.com
and remove server1.example.com and server1 from the 127.0.0.1 line.
Configure Additional IP Addresses
(This section is totally optional. It just shows how to add additional
IP addresses to your network interface eth0 if you need more than one IP
address. If you're fine with one IP address, you can skip this section.)
Let's assume our network interface is eth0.
Then there is a file /etc/sysconfig/network-scripts/ifcfg-eth0
which looks like this:
$ sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82566MM Gigabit Network Connection
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
GATEWAY=192.168.0.1
HWADDR=00:1E:37:D4:95:4D
IPADDR=192.168.0.166
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
Now we want to create the virtual interface eth0:0 with the IP address 192.168.0.167.
All we have to do is to create the file
/etc/sysconfig/network-scripts/ifcfg-eth0:0
which looks like this:
(we can leave out the HWADDR line as it is the same physical network card)
$ sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0:0 DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=192.168.0.255
GATEWAY=192.168.0.1
IPADDR=192.168.0.167
NETMASK=255.255.255.0
NETWORK=192.168.0.0
Afterwards we have to restart the network:
(you must stop NetworkManager first, before restart network
$ sudo /etc/init.d/NetworkManager stop
$ sudo chkconfig NetwrokManager off
$ sudo chkconfig network on
)
$ /etc/init.d/network restart
You might also want to adjust /etc/hosts
after you have added new IP addresses, although this is not necessary.
Now run
$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:1E:37:D4:95:4D
inet addr:192.168.0.166 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::21e:37ff:fed4:954d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:30293 errors:0 dropped:0 overruns:0 frame:0
TX packets:32596 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:17311404 (16.5 MiB) TX bytes:10236595 (9.7 MiB)
Memory:fe000000-fe020000
eth0:0 Link encap:Ethernet HWaddr 00:1E:37:D4:95:4D
inet addr:192.168.0.167 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Memory:fe000000-fe020000
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:44 errors:0 dropped:0 overruns:0 frame:0
TX packets:44 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2540 (2.4 KiB) TX bytes:2540 (2.4 KiB)