标签:col table local ice car ethernet ddr dhcp服务器 sts
1.查看网卡信息和网络相关配置
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 #ens33:物理网卡名称 网卡最大传输单元(字节)
inet 192.168.86.132 netmask 255.255.255.0 broadcast 192.168.86.255 #ip地址(动态dhcp或静态) 子网掩码
inet6 fe80::20c:29ff:fec2:ce44 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c2:ce:44 txqueuelen 1000 (Ethernet) #MAC地址
RX packets 114 bytes 12256 (11.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 121 bytes 16352 (15.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 #回环网卡
inet 127.0.0.1 netmask 255.0.0.0 #ip地址(默认是127.0.0.1)
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
改变网卡ip地址
[root@localhost ~]# ifconfig ens33 192.168.86.137/24
DNS配置文件:
[root@localhost ~]# cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
search localdomain
nameserver 192.168.86.2 #DNS服务器地址
配置网关:
[root@localhost ~]# route add default gw 192.168.86.1 netmask 255.255.255.0
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.86.1 255.255.255.0 UG 0 0 0 ens33 #访问255.255.255.0子网掩码下的所有ip地址都通过网关192.168.86.1
192.168.86.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 #访问255.255.255.0下的192.168.86.0区段ip不通过网关
[root@localhost ~]# route del default gw 192.168.86.1
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.86.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
以上修改在重启network.service之后失效:
[root@localhost ~]# systemctl restart network.service
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.86.132 netmask 255.255.255.0 broadcast 192.168.86.255
inet6 fe80::20c:29ff:fec2:ce44 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c2:ce:44 txqueuelen 1000 (Ethernet)
RX packets 205 bytes 22558 (22.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 256 bytes 35087 (34.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2.永久性修改网络配置
网络配置文件保存在/etc/sysconfig/network-scripts/文件夹下,每一块网卡对应的配置文件名称为ifcfg-网卡名。
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet #以太网协议
BOOTPROTO=dhcp #通过dhcp服务器获取ip地址
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=93020a64-1466-4aa0-8a25-debde3b0fd9d
DEVICE=ens33
ONBOOT=yes #网络服务启动时自动加载
将ip地址改为静态
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.86.132
NETMASK=255.255.255.0
GATEWAY=192.168.86.2
DNS1=172.16.23.168
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=93020a64-1466-4aa0-8a25-debde3b0fd9d
DEVICE=ens33
ONBOOT=yes
[root@localhost ~]# systemctl restart network.service
3.本地DNS解析
DNS服务器会自动把域名解析成ip地址:
[root@localhost ~]# ping www.baidu.com
PING www.baidu.com (119.75.216.20) 56(84) bytes of data.
可以通过/etc/hosts文件进行本地解析:
[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.86.133 python-web1
[root@localhost ~]# ping python-web1
PING python-web1 (192.168.86.133) 56(84) bytes of data.
4.查看和设置主机名
[root@python-server ~]# hostname
python-server
[root@python-server ~]# hostnamectl set-hostname python-main
重新打开终端后会发现左边的主机名已更改:
[root@python-main ~]# hostname
python-main
标签:col table local ice car ethernet ddr dhcp服务器 sts
原文地址:http://www.cnblogs.com/Icarus1900/p/7668349.html