Files that affect IP addresses, gateways, and DNS settings in Linux

Source: Internet
Author: User
Files that affect IP addresses, gateways, and DNS settings in Linux
2008-07-09 17:24:46

Files that affect IP addresses, gateways, and DNS settings in Linux

IP:/etc/sysconfig/network-scripts/ifcfg-eth0

 

Default Gateway:/etc/sysconfig/Network

DNS:/etc/resolv. conf

 

[Root @ fedora ~] # Strings/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0
Bootproto = static
Broadcast = 172.16.0000255
Hwaddr = 00: 03: FF: 64: 07: 51
Ipaddr = 172.16.1.78
Netmask = 255.255.0.0
Network = 172.16.0.0
Onboot = Yes
Type = Ethernet

[Root @ fedora ~] # Strings/etc/sysconfig/Network
Networking = Yes
Hostname = fedora.cqxhsd.org
Gateway = 172.16.100.254

[Root @ fedora ~] # Strings/etc/resolv. conf
Nameserver 172.16.1.107
Search cqxhsd.org

2. to connect the two NICs to the corresponding network, use the ifconfig command. In this example, you can configure the following: # ifconfig 166.166.64.1 running route 192.0 eth0 up # ifconfig 166.166.128.1 running route 192.0 eth1 up. The ifconfig command informs the Linux kernel of some network interfaces such as software delivery and Ethernet, so that Linux can use them. The two commands mean that the IP address 166.166.64.1 is allocated to the network adapter eth0, The subnet mask is 255.192.0, the IP address 166.166.128.1 is allocated to the network adapter eth1, And the subnet mask is 255.255.192.0; the up parameter indicates that the configuration takes effect immediately. ("#" At the beginning of the command line is the command input prompt of the Super User in Linux)

After the NIC parameters are configured, you must configure the system route table correctly and enable the IP forwarding function. In Linux, you can use multiple routing protocols. For the sake of simplicity, this article only introduces the configuration of Static Routing. When configuring a route table, you should first use the router-N command to list the content of the current route table, delete all the incorrect routes, and then use the route add command to add static routes.

Run the following command to delete a route: # route del-net |-host name netmask netmask_name; where-net is the route to the network and-host is the route to the host; select one of the two parameters as needed. Name indicates the IP address of the network or host to be deleted, and netmask_name indicates the IP address of the subnet mask.

Then add the following two items: # route add-net 166.166.64.0 netmask route 192.0 eth0 # route add-net route netmask route 192.0 eth1 these two lines of commands will make all packets sent to the 166.166.64.0 network should be sent through the eth0 Nic, packets sent to the 166.166.128.0 network must be sent through the eth1 network adapter.

Finally, run the command # Echo 1>/proc/sys/NET/IPv4/ip_forward to start the IP forwarding function of the system. If you want to disable IP Forwarding, replace parameter 1 in the preceding command with 0.

Now, the gateway configuration is complete. I have used the ping command (for example, Ping 166.166.192.5-T) on several computers in the two subnets and the method of searching for network neighbors to perform tests; all the results can be pinged to other machines on the network, and computers on the network can be quickly found. This proves that the gateway is correctly set. If the ping fails, you should carefully check whether the network hardware, such as the network cable, hub, and nic, is normal.

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.