Linux Configuration IP Gateways and DNS

Source: Internet
Author: User
Tags nameserver

Original address: http://blog.csdn.net/ztz0223/article/details/5800665

It's easy to configure IP under Linux, and it's not as complex as it says online, my Linux system is Rhel 5.5.


As follows:

[Email protected] ~]#
[Email protected] ~]# cd/etc
[Email protected] etc]# CD sysconfig/
[Email protected] sysconfig]# CD network-scripts/

[Email protected] network-scripts]# dir
Ifcfg-eth0 ifdown-ippp ifdown-ppp ifup 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

[Email protected] network-scripts]# pwd
/etc/sysconfig/network-scripts


[Email protected] network-scripts]#

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

[Email protected] network-scripts]#
[email protected] network-scripts]# cat Ifcfg-eth0
# Realtek Semiconductor Co., 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, you can copy the Ifcfg-eth0 and name it ifcfg-eth0:1 as follows:

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
[Email protected] network-scripts]#

If you want to continue adding it, continue to build the configuration file Ifcfg-eth0:n,n from 1 to any positive integer, the first is Ifcfg-eth0, then ifcfg-eth0:n can be, in fact, the configuration file naming relationship seems to be small.

Here to Eth0 added two IP, remember that the corresponding device devices are the same eth0, but after each IP corresponding device needs to be slightly modified, the first IP is eth0, after the start from eth0:0 to add, eth0:0, Eth0:1, Eth0:2

Wait a minute. One IP corresponds to a profile (Ifcfg-eth0, ifcfg-eth0:1, ifcfg-eth0:2 ...), within each configuration file, corresponding to a device (eth0, eth0:0, eth0:1 ...).

Here, the IP is 10.63.198.234 and 10.63.198.249, here are some explanations for these parameters:

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 stands for Devices, Linux can have a lot of devices Ethernet interface is the beginning of the ETH, Onboot Yes indicates that the system starts to start the network card, dhcp_hostname the host name for network resolution, and then
ipaddr=10.63.198.234
netmask=255.255.255.0
gateway=10.63.198.254
The separate code is the IP, subnet mask, and gateway.

The next step is to set up DNS, which in the file:
/etc/resolv.conf inside, as follows:

[email protected] etc]# cat resolv.conf
; Generated By/sbin/dhclient-script
NameServer 192.168.1.1
NameServer 10.67.1.1
[Email protected] etc]#
Inside the nameserver is the domain name resolution server address, if there are many can be as above, add more than nameserver can.

Finally, use the command to turn the network connection on and off:

/sbin/ifup eth0
/sbin/ifdown eth0
/etc/init.d/network restart

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

Service Network restart

Linux configuring IP Gateways and DNS (RPM)

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.