Modify IP, DNS, and route command line settings in Linux
1)Ubuntu or Debian
1. Set the IP address in the 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
2. Restart the NIC:/etc/init. d/networking restart
2)RedHat Linux version
1. Set the IP address in the command line:
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!
1. Use commands to set the IP address of ubuntu
1. Set ipsudo ifconfig eth0 192.168.7.70 netmask 255.255.255.0
2. Set the gateway sudo route add default GW 192.168.7.1
3. Set DNS
However, after this setting, the IP address does not exist at the next boot.
Ii. Improvement Method: directly modify the system configuration file
The Ubuntu network configuration file is:/etc/Network/interfaces
1. Configure the NIC in DHCP Mode
Edit the configuration file sudo VI/etc/Network/interfaces
Replace eth0 with the following rows:
Auto eth0
Iface eth0 innet DHCP
Run the following command to make the network settings take effect:
Sudo/etc/init. d/networking restart
You can also use the Command world input to obtain the sudo dhclient eth0 address.
2. Use the NIC to configure a static IP Address
Edit the configuration file sudo VI/etc/Network/interfaces.
Replace eth0 with the following rows.
Auto eth0
Iface eth0 Inet static
Address 192.168.7.70
Gateway 192.168.7.1
Netmask 255.255.255.0
# Network 192.168.1.0
# Broadcast 192.168.1.255
Use commands to make the network settings take effect
Sudo/etc/init. d/networking restart
3. If you want to set the second IP Address
Auto eth0: 1
Iface eth0: 1 Inet static
Address 192.168.1.60
Netmask 255.255.255.0
Network x. x
Broadcast x. x
Gateway x. x
Same as above
Verify whether the configuration is successful. You can ping