Configure IP Gateway and DNS in Linux

Source: Internet
Author: User
Tags nameserver

It is easy to configure IP addresses in Linux, which is not as complicated as I mentioned on the Internet. My Linux system is RHEL 5.5.

As follows:

[Root @ btazuo ~] #
[Root @ btazuo ~] # Cd/etc
[Root @ btazuo etc] # cd sysconfig/
[Root @ btazuo sysconfig] # cd network-scripts/

 

[Root @ btazuo network-Scripts] # dir
Ifdown-ippp ifdown-ppp ifup-ippp IFUP-plip ifup-Sit net. hotplug
Ifcfg-Lo ifdown-IPsec ifdown-routes IFUP-aliases IFUP-IPsec IFUP-plusb IFUP-Sl network-Functions
Ifdown ifdown-ipv6 ifdown-Sit IFUP-bnep ifup-ipv6 IFUP-post IFUP-tunnel network-functions-ipv6
Ifdown-bnep ifdown-ISDN ifdown-Sl IFUP-eth IFUP-ipx ifup-ppp ifup-Wireless
Ifdown-eth ifdown-post ifdown-tunnel IFUP-Ib IFUP-isdn ifup-routes init. ipv6-global

[Root @ btazuo network-Scripts] # pwd
/Etc/sysconfig/network-Scripts

[Root @ btazuo network-Scripts] #

Here we can modify the ifcfg-eth0 file, because my file is OK, so, just show and explain:

[Root @ btazuo network-Scripts] #
# Cat ifcfg-eth0 [root @ btazuo network-Scripts] #
# RealTek semiconduco., Ltd. RTL-8139/8139c/8139c +
Device = eth0
Bootproto = none
Hwaddr = 00: 11: D8: C5: 7c: 8f
Onboot = Yes
Dhcp_hostname = btazuo
Ipaddr = 10.63.198.234
Netmask = 255.255.255.0
Gateway = 10.63.198.254
Type = Ethernet
Userctl = No
Ipv6init = No
Peerdns = Yes

 

If you want to add an IP address to the same Nic, copy the ifcfg-eth0 and name it ifcfg-eth0: 1 with the following content:

Device = eth0: 0
Bootproto = none
Hwaddr = 00: 11: D8: C5: 7c: 8f
Onboot = Yes
Dhcp_hostname = btazuo
Ipaddr = 10.63.198.249
Netmask = 255.255.255.0
Gateway = 10.63.198.254
Type = Ethernet
Userctl = No
Ipv6init = No
Peerdns = Yes
[Root @ btazuo network-Scripts] #

 

If you want to continue adding, continue generating the profile ifcfg-eth0: N, N from 1 to any positive integer, the first is the ifcfg-eth0, followed by the ifcfg-eth0: N, in fact, the name of the configuration file does not seem to have a big relationship.

 

Two IP addresses are added to eth0. Remember that the device of the corresponding device is the same eth0, but the device corresponding to each IP address needs to be slightly modified. The first IP address is eth0, and then start from eth0: 0, eth0: 0, eth0: 1, eth0: 2

And so on. An IP corresponds to a configuration file (ifcfg-eth0, ifcfg-eth0: 1, ifcfg-eth0: 2 ....), each configuration file corresponds to a device (eth0, eth0: 0, eth0: 1 ......).

 

Here, the IP addresses are 10.63.198.234 and 10.63.198.249, which are explained here:

Device = eth0
Bootproto = none
Hwaddr = 00: 11: D8: C5: 7c: 8f
Onboot = Yes
Dhcp_hostname = btazuo
Ipaddr = 10.63.198.234
Netmask = 255.255.255.0
Gateway = 10.63.198.254
Type = Ethernet

 

Device indicates a device. in Linux, there may be many Ethernet interfaces starting with ETH. If onboot is yes, it indicates that the NIC is started when the system starts and dhcp_hostname indicates the host name for network resolution. Next
Ipaddr = 10.63.198.234
Netmask = 255.255.255.0
Gateway = 10.63.198.254
The code is IP address, subnet mask, and gateway respectively.

 

The next step is to set DNS, which is in the file:
In/etc/resolv. conf:

[Root @ btazuo etc] # Cat resolv. conf
; Generated by/sbin/dhclient-script
Nameserver 192.168.1.1
Nameserver 10.67.1.1
[Root @ btazuo etc] #
The nameserver is the server address for domain name resolution. If there are multiple nameservers, you can add multiple nameservers.

Finally, run the following command to enable or disable the network connection:

/Sbin/IFUP eth0
/Sbin/ifdown eth0
/Etc/init. d/network restart

 

Of course, you can also directly restart the system's network:

Service Network restart

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.