How to configure IP addresses in Linux

Source: Internet
Author: User
Tags nameserver ssh port

In Linux, how do I set IP addresses? We can use commands to set the IP address, but the prerequisite for this method is that the user needs the root permission. The nic ip Address Configuration information is stored in the/etc/sysconfig/network-script/ifcfg-eth0 file of the Linux system. The specific format is:
# Cat ifcfg-eth0 [root @ localhost network-Scripts] #

Device = eth0

Bootproto = none

Onboot = Yes

Type = Ethernet

Netmask = 255.255.255.0

Ipaddr = IP Address

Userctl = No

Peerdns = Yes

Gateway = gateway address (IP address of the router)

The following is an example of how to set IP addresses in Linux.

# Ifconfig eth0 192.168.0.1 or modify the ifcfg-eth0 under/etc/sysconfig/network-scripts/

# Vi/etc/syssconfig/network-scripts/ifcfg-eth0

Device = eth0

Bootproto = static

Hwaddr =; here is the physical address of your Nic. You do not need to enter the detected Nic.

Onboot = Yes

Ipaddr = 192.168.0.1

Netmask = 255.255.255.0

Network = 192.168.1.0

Broadcast = 192.168.1.255

Gateway =; enter the IP address of your gateway and router.

Save and exit

#/Sbin/service network restart

If the Enable Nic is OK, the IP address is successfully set. In addition, we can use ifconfig eth0 to display the current IP address to confirm whether it is set correctly.

Use the following command:

/Etc/init. d/network reload command or service network [command]

Re-import the file to enable Network startup.

Ifconfig eth0 192.168.1.10 netmask 255.255.255.0 // configure the IP address
Ifconfig eth0 up | down // activation, disable the device eth0

Route add default GW 192.168.1.1 // configure the Default Gateway

Temporarily configure DNS resolution
Echo "nameserver 211.98.1.28">/etc/resolv. conf

In Linux, how do I set IP addresses? We can

 
The command is used to set the IP address. However, the prerequisite for this method is that the user needs the root permission. The nic ip Address Configuration information is stored in the/etc/sysconfig/network-script/ifcfg-eth0 file of the Linux system. The specific format is:

# Cat ifcfg-eth0 [root @ localhost network-Scripts] #

Device = eth0

Bootproto = none

Onboot = Yes

Type = Ethernet

Netmask = 255.255.255.0

Ipaddr = IP Address

Userctl = No

Peerdns = Yes

Gateway = gateway address (IP address of the router)

The following is an example of how to set IP addresses in Linux.

# Ifconfig eth0 192.168.0.1 or modify the ifcfg-eth0 under/etc/sysconfig/network-scripts/

# Vi/etc/syssconfig/network-scripts/ifcfg-eth0

Device = eth0

Bootproto = static

Hwaddr =; here is the physical address of your Nic. You do not need to enter the detected Nic.

Onboot = Yes

Ipaddr = 192.168.0.1

Netmask = 255.255.255.0

Network = 192.168.1.0

Broadcast = 192.168.1.255

Gateway =; enter the IP address of your gateway and router.

Save and exit

#/Sbin/service network restart

If the Enable Nic is OK, the IP address is successfully set. In addition, we can use ifconfig eth0 to display the current IP address to confirm whether it is set correctly.

Use the following command:

/Etc/init. d/network reload command or service network [command]

Re-import the file to start the network.

In Linux, modify the IP address, DNS, and route command line to set the IP address in the Ubuntu command line.
CAT/etc/Network/interfaces

# This file describes the network interfaces available on your system

# And how to activate them. For more information, see interfaces (5 ).

# The loopback network interface

Auto Lo

Iface lo Inet loopback

# The primary network interface

Auto eth0

Iface eth0 Inet static

Address 192.168.1.104

Netmask 255.255.255.0

Network 192.168.1.0

Broadcast 192.168.1.255

Gateway 192.168.1.2

# DNS-* options are implemented by the resolvconf package, if installed

DNS-nameservers 58.22.96.66 218.104.128.106 202.101.138.8

DNS-search. com

Restart the NIC:/etc/init. d/networking restatr

Set the IP address in the command line of RedHat Linux:

Ifconfig eth0 new IP

Then edit/etc/sysconfig/network-scripts/ifcfg-eth0 and modify the IP

1. Modify the IP address

[Aeolus @ database network-Scripts] $ VI ifcfg-eth0

Device = eth0

Onboot = Yes

Bootproto = static

Ipaddr = 219.136.241.211

Netmask = 255.255.255.255.128

Gateway = 219.136.241.254

2. Modify the Gateway

VI/etc/sysconfig/Network

Networking = Yes

Hostname = Aaron

Gateway = 192.168.1.1

3. Modify DNS

[Aeolus @ dB etc] $ VI resolv. conf

Nameserver 202.96.128.68

Nameserver 219.136.241.206

4. Restart Network Configuration

/Etc/init. d/network restart v. Example

1. Modify the IP address

Effective immediately:

# Ifconfig eth0 192.168.0.20 netmask 255.255.255.0

Start effective:

Modify/etc/sysconfig/network-scripts/ifcfg-eth0

2. Modify the Default Gateway

Effective immediately:

# Route add default GW 192.168.0.254

Start effective:

Modify/etc/sysconfig/network-scripts/ifcfg-eth0

Modify DNS

Modify/etc/resolv. conf

The modification takes effect immediately and starts as well.

3. Modify host name

Effective immediately:

# Hostname FC2

Start effective:

Modify/etc/sysconfig/Network

PS:

Device = eth0

Bootproto = static

Ipaddr = 192.168.8.85

Netmask = 255.255.248.0

Gateway = 192.168.8.1

Hwaddr = 00: 0uu3: 47: 2C: D5: 40

Onboot = Yes

4: Add a Linux Startup item:

VI/etc/rc. d/rc. Local

Modify the ssh port number in Linux

Modify the ssh port number of the Linux system. applicable to both Linux and UNIX: modify the configuration file/etc/ssh/sshd_config and change the port number to a new port.ProgramUsed), such as 10022, and then

Kill-HUP 'cat/var/run/sshd. Pi. Note: The existing connection will not be disconnected because kill-hup'

Modify the ssh port number in Linux

Linux and UNIX operating systems are applicable:

Modify the configuration file/etc/ssh/sshd_config and change the port in to a new port (this port must be used by no program), such as 10022,

Then kill-HUP 'cat/var/run/sshd. Pi.

Note: The existing connection will not be disconnected because kill-HUP 'cat/var/run/sshd. the PID is the one that hup listens to. The established connection (different PID) will not be disconnected.

To re-enable and use the new port to log on, log off with the exit command under the current Logon account and log on to the new port.
In Linux, modify the IP address, DNS, and route command line to set the IP address in the Ubuntu command line.
CAT/etc/Network/interfaces

# This file describes the network interfaces available on your system

# And how to activate them. For more information, see interfaces (5 ).

# The loopback network interface

Auto Lo

Iface lo Inet loopback

# The primary network interface

Auto eth0

Iface eth0 Inet static

Address 192.168.1.104

Netmask 255.255.255.0

Network 192.168.1.0

Broadcast 192.168.1.255

Gateway 192.168.1.2

# DNS-* options are implemented by the resolvconf package, if installed

DNS-nameservers 58.22.96.66 218.104.128.106 202.101.138.8

DNS-search. com

Restart the NIC:/etc/init. d/networking restatr

Set the IP address in the command line of RedHat Linux:

Ifconfig eth0 new IP

Then edit/etc/sysconfig/network-scripts/ifcfg-eth0 and modify the IP

1. Modify the IP address

[Aeolus @ database network-Scripts] $ VI ifcfg-eth0

Device = eth0

Onboot = Yes

Bootproto = static

Ipaddr = 219.136.241.211

Netmask = 255.255.255.255.128

Gateway = 219.136.241.254

2. Modify the Gateway

VI/etc/sysconfig/Network

Networking = Yes

Hostname = Aaron

Gateway = 192.168.1.1

3. Modify DNS

[Aeolus @ dB etc] $ VI resolv. conf

Nameserver 202.96.128.68

Nameserver 219.136.241.206

4. Restart Network Configuration

/Etc/init. d/network restart v. Example

1. Modify the IP address

Effective immediately:

# Ifconfig eth0 192.168.0.20 netmask 255.255.255.0

Start effective:

Modify/etc/sysconfig/network-scripts/ifcfg-eth0

2. Modify the Default Gateway

Effective immediately:

# Route add default GW 192.168.0.254

Start effective:

Modify/etc/sysconfig/network-scripts/ifcfg-eth0

Modify DNS

Modify/etc/resolv. conf

The modification takes effect immediately and starts as well.

3. Modify host name

Effective immediately:

# Hostname FC2

Start effective:

Modify/etc/sysconfig/Network

PS:

Device = eth0

Bootproto = static

Ipaddr = 192.168.8.85

Netmask = 255.255.248.0

Gateway = 192.168.8.1

Hwaddr = 00: 0uu3: 47: 2C: D5: 40

Onboot = Yes

4: Add a Linux Startup item:

VI/etc/rc. d/rc. Local

Modify the ssh port number in Linux

Modify the ssh port number of a Linux system. applicable to both Linux and UNIX: modify the configuration file/etc/ssh/sshd_config, change the port in to a new port (this port must be used by no program), such as 10022, and then

Kill-HUP 'cat/var/run/sshd. Pi. Note: The existing connection will not be disconnected because kill-hup'

Modify the ssh port number in Linux

Linux and UNIX operating systems are applicable:

Modify the configuration file/etc/ssh/sshd_config and change the port in to a new port (this port must be used by no program), such as 10022,

Then kill-HUP 'cat/var/run/sshd. Pi.

Note: The existing connection will not be disconnected because kill-HUP 'cat/var/run/sshd. the PID is the one that hup listens to. The established connection (different PID) will not be disconnected.

To re-enable and use the new port to log on, log off with the exit command under the current Logon account and log on to the new port.

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.