How to change IP addresses for Linux

Source: Internet
Author: User
You only need to create a file named ifcfg-eth0: 0 in the/etc/sysconfig/network-scripts directory,

First, use the command to modify the changes (the changes take effect immediately and the restart fails)

# Ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up

Note:

Eth0 is the first Nic, and the others are eth1, eth *
192.168.0.1 is the IP address configured for the first Nic
Netmask 255.255.255.255.0 is configured with a subnet mask.
Up indicates immediate activation.
For more information about ifconfig parameters, see related help.

Gateway:
# Route add default gw 192.168.30.1 eth0

Dns:
# Vi etc/resolv. conf
Nameserver 8.8.8.8
Nameserver 4.4.4.4

To take effect again, write these to the file location/etc/rc. d/rc. local in the startup script rc. local.

Type 2: modify the configuration document (you need to restart the network configuration to always take effect)

Configuration file location:/etc/sysconfig/network-scripts/ifcfg-eth0 main settings parameters are as follows:

DEVICE = eth0 # physical DEVICE name
IPADDR = 192.168.1.10 # IP address
NETMASK = 255.255.255.0 # mask value
NETWORK = 192.168.1.0 # NETWORK address (optional)
BROADCAST = 192.168.1.255 # BROADCAST address (optional)
GATEWAY = 192.168.1.1 # GATEWAY address
ONBOOT = yes # [yes | no] (whether to activate the device during boot)
NM_CONTROLLED # [yes | no] (whether it is controlled by a service called networkmanager)
USERCTL = no # [yes | no] (whether non-root users can control the device)
BOOTPROTO = static # [none | static | bootp | dhcp] (no protocol used during boot | static allocation | BOOTP protocol | DHCP protocol)

INSTANCE. the default configuration for Centos6.0 is as follows:

DEVICE = "etho"
HWADDR = "00: 0C: 29: 60: 13: AE"
NM_CONTROLLED = "yes"
ONBOOT = "no"

Here, our system is unable to access the internet. There are two ways to enable the system to access the Internet.

1. if your router has a DHCP server enabled, use DHCP to automatically obtain the IP address, as shown below:

DEVICE = "etho"
BOOTPROTO = dhcp
HWADDR = "00: 0C: 29: 60: 13: AE"
NM_CONTROLLED = "yes"
ONBOOT = "yes"

Then restart the network to take effect.

2. set static IP addresses

DEVICE = "eth0"
HWADDR = "00: 0C: 29: 60: 13: AE"
NM_CONTROLLED = "yes"
IPADDR = 192.168.239.200
GATEWAY = 192.168.239.2
NETMASK = 255.255.255.0
ONBOOT = "yes"

Save. after modification, add the dns server. the configuration file is under/etc/resolv. conf. for the method, refer to the first DNS adding method.
After that, restart the network and ping blog.micxp.com. if you can ping blog.micxp.com, your system can access the internet normally.

Note: bind two IP addresses to a single NIC

Linux device configuration files are stored in/etc/sysconfig/network-scripts,
For the first Ethernet device, the configuration file name is generally ifcfg-eth0
To bind one more IP address to the first device,
You only need to create a file named ifcfg-eth0: 0 in the/etc/sysconfig/network-scripts directory,

Content example:

DEVICE = "eth0: 0"
IPADDR = "211.100.10.119"
NETMASK = "255.255.255.0"

If you need to bind another IP address, you only need to add the file name to the eth0: x of the DEVICE in the file. LINUX supports up to 255 IP aliases.

There are multiple methods:
1: # service network restart
2: #/etc/init. d/network restart
3: # ifdown eth0
# Ifup eth0
4: # ifconfig eth0 down
# Ifconfig eth0 up

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.