I. modify the configuration file, and the settings will not be lost after restart
[Red Hat Linux/CentOS]
Use ifconfig to view the network port used:

[root@localhost /]# ifconfig

Modify the corresponding network interface profile:

[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens192
UUID=dcb6f08a-1e19-44fe-9427-479fcebc1cd3
DEVICE=ens192
ONBOOT=yes
IPADDR=10.8.3.40
NETMASK=255.255.255.0
GATEWAY=10.8.3.254
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no
DNS1=10.8.1.2

Restart the network card:

[root@localhost network-scripts]# service network restart

[Ubuntu]
Use ifconfig to view the network port used:

[root@localhost /]# ifconfig

Modify the configuration network interface file:

root@ubuntu14:/# vi /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
#This is an autoconfigured IPv6 interface
auto eth1
iface eth1 inet static
address 10.8.3.105
netmask 255.255.255.0
gateway 10.8.3.254

Amending DNS:

root@ubuntu14:/etc# vi /etc/resolv.conf
#Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#DO NOT EDIT THIS FILE BY HAND – YOUR CHANGES WILL BE OVERWRITTEN
nameserver 10.8.1.25
nameserver 8.8.8.8

Restart the network card:

root@ubuntu14:/etc# service networking restart


II. The command is modified, and the settings are lost after restart
ifconfig command can only be executed under root

[root@localhost /]# ifconfig eth0 10.8.3.159 netmask 255.255.255.0
[root@localhost /]#route add default gw 10.8.3.254

III. use of other commands
1) close or restart the network port

[root@localhost /]# ifconfig eth0 down
[root@localhost /]# ifconfig eth0 up

2) view routing table

root@ubuntu14:/# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.8.3.254 0.0.0.0 UG 0 0 0 eth1
10.8.3.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1