Linux IP Address Modification

Source: Internet
Author: User
Tags nameserver


In Linux, IP addresses were dynamically assigned by automatic IP addresses. Although the IP addresses obtained each time are the same, I decided to set an ip Address by myself. Enter the command: [root @ localhost ~] # Ifconfig eth0 219.246.177.160 netmask 255.255.255.255.0 up ping the ip address in the following 177 CIDR blocks can be pinged, but other CIDR blocks cannot be pinged [root @ localhost ~] # Ping 219.246.183.1connect: Network is unreachableJava code www.2cto.com [root @ localhost ~] # Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 219.246.177.0*255.255.255.0 U 0 0 0 eth0 Java code [root @ localhost ~] # Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 219.246.177.0*255.255.255.0 U 0 0 0 eth0 No Default Gateway is set. Set gateway [root @ localhost ~] # Route add default gw 219.246.177.1route add default gw 61.144.47.225 then view the route table: Java code [root @ localhost ~] # Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 219.246.177.0*255.255.255.0 U 0 0 0 eth0 default 255.0.0.0.0 UG 0 0 0 eth0 Java code www.2cto.com [root @ localhost ~ # Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 219.246.177.0*255.255.255.0 U 0 0 0 eth0 default 219.246.177.1 0.0.0.0 UG 0 0 0 eth0
Added the default gateway. In this case, you can ping other network segments. However, this modification will become invalid after the restart. To make the modified ip permanently effective, you must modify the configuration file/etc/sysconfig/network-scrips/ifcfg-eth0. This is because the configuration parameters of this file are loaded when the machine starts. Modify this file: Java code [root @ localhost ~] # Vi/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE = eth0 # network DEVICE name, # BOOTPROTO = dhcp # Use Dynamic IP Address Allocation when starting eth0 interface # Here is the static IP address, so block this sentence BOOTPROTO = static # Use the static IP address to assign HWADDR = 00: E0: 4C: 61: 71 when starting the eth0 interface: e3 # MAC address IPADDR = 219.246.177.160 # set IP address NETMASK = 255.255.255.0 # Set sub-King mask GATEWAY = 219.246.177.1 # Set gateway onboot = yes # Start Java code at startup [root @ localhost ~] # Vi/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE = eth0 # network DEVICE name, # BOOTPROTO = dhcp # Use Dynamic IP Address Allocation when starting eth0 interface # Here is the static IP address, so block this sentence BOOTPROTO = static # Use the static IP address to assign HWADDR = 00: E0: 4C: 61: 71 when starting the eth0 interface: e3 # MAC address IPADDR = 219.246.177.160 # set IP address NETMASK = 255.255.255.0 # Set sub-King mask GATEWAY = 219.246.177.1 # Set gateway onboot = yes # Start Java code DEVICE = eth0 BOOTPROTO = none HWADDR = 00: 13: D3: 90: 95: 4D ONBOOT = yes TYPE = Ethernet NETMASK = zookeeper 248 www.2cto.com IPADDR = paiuserctl = no route 6init = no PEERDNS = yes IGATEWAY = gategateway = register Java code DEVICE = eth0 BOOTPROTO = none HWADDR = 00: 13: D3: 90: 95: 4D ONBOOT = yes TYPE = Ethernet NETMASK = 255.255.255.255.248 IPADDR = 61.144.47.228 USERCTL = no 255.6init = no PEERDNS = yes IGATEWAY = 61.144.47.225 GATEWAY = modified, to take effect without restarting the modified configuration. Enter the command [root @ localhost ~] # Ifdown eth0 disable the eth0 network interface, and then enter the following command to restart the eth0 interface [root @ localhost ~] # The ifup eth0 command reads the corresponding parameters under/etc/sysconfig/network-scripts/to make the configuration take effect. Or enter [root @ localhost ~] #/Etc/init. d/network restart www.2cto.com restart the parameters of the entire network. The/etc/init. d/network file is also loaded at startup. In this way, you can solve the problem of IP settings. To set DNS, edit the Java code [root @ localhost ~] in the/etc/resolv. conf file. # Vi/etc/resolv. conf nameserver 202.201.0.131 nameserver 202.201.0.132 nameserver 202.201.89.131 search lzu.edu.cn Java code [root @ localhost ~] # Vi/etc/resolv. conf nameserver 202.201.0.131 nameserver 202.201.0.132 nameserver 202.201.89.131 search lzu.edu.cn after configuration, of course, you must enter [root @ localhost ~] #/Etc/init. d/network restart, restart the parameters of the entire network. To take effect.

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.