linux使用配置文件配置网络(linux配置网络的方法)

1.Centos6网络配置•查看IP地址

linux使用配置文件配置网络(linux配置网络的方法)

1.Centos 6网络配置

• 查看 IP 地址

 [root@localhost ~]# ifconfigeth0      Link encap:Ethernet  HWaddr FA:79:75:1E:74:00            inet addr:10.154.0.8  Bcast:10.154.0.255  Mask:255.255.255.0          inet6 addr: fe80::f879:75ff:fe1e:7400/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:176883 errors:0 dropped:0 overruns:0 frame:0          TX packets:112967 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:18585161 (17.7 MiB)  TX bytes:18936319 (18.0 MiB)lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:132 errors:0 dropped:0 overruns:0 frame:0          TX packets:132 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:15346 (14.9 KiB)  TX bytes:15346 (14.9 KiB)

• 修改 IP 地址

 [root@bjdb4 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0   #网卡驱动名称 TYPE=EthernetUUID=4c0289bd-ca9b-433c-85bf-8b593d5b4c42   #网卡 UUID 号 ONBOOT=yes        #网卡开启状态 NM_CONTROLLED=yesBOOTPROTO=static    #把 DHCP 状态修改城 staticHWADDR=28:80:23:B8:B4:88   #mac 地址 IPADDR=172.18.1.40     #IP 地址 PREFIX=24    #子网掩码位数 GATEWAY=172.18.1.254  #网关 DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME=\"System eth0\"    #网卡名称

• 修改 DNS

[root@1234 ~]$ vi /etc/resolv.conf# Generated by NetworkManager# No nameservers found; try putting DNS servers into your# ifcfg files in /etc/sysconfig/network-scripts like so:## DNS1=xxx.xxx.xxx.xxx# DNS2=xxx.xxx.xxx.xxx# DOMAIN=lab.foo.com bar.foo.comnameserver 202.198.98.167     #修改为当地运营商的 DNS 地址 nameserver 8.8.8.8

• 修改网关地址

[root@1234 ~]$ vi /etc/sysconfig/networkNETWORKING=yes         HOSTNAME=1234         #主机名 GATEWAY=172.18.1.254   #网关地址

• 静态路由设置(根据需要配置)

– 查看静态路由

 [root@1234 ~]# route -nKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface172.18.1.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth00.0.0.0         172.18.1.254    0.0.0.0         UG    0      0        0 eth0

– 设置永久静态路由

 [root@1234 ~]# vi /etc/rc.local#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don\'t# want to do the full Sys V style init stuff.touch /var/lock/subsys/localroute add -net 192.168.3.0/24 dev eth0   #新增路由地址段与子网掩码,出口网卡名称 route add -net 192.168.2.0/24 gw 192.168.2.254    #新增路由地址段与子网掩码,网关地址 [jqsoft@bjdb4 ~]$ vi /etc/sysconfig/static-routes any net 192.168.3.0/24 gw 192.168.3.254  #新增路由地址段与子网掩码,出口网关地址 any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129  #新增路由地址段与子网掩码,出口网关地址 [root@1234 ~]# vi /etc/sysconfig/network-script/route-eth0#默认格式:network/prefix via gateway dev intf0.0.0.0/0 via 172.16.10.2 dev eth0  #新增路由

• 重启网卡

[root@1234 ~]#service network restart

2.Centos 7 网络配置

• 查看 IP 地址

[root@localhost ~]# ifconfigens33: flags=4163  mtu 1500        inet 192.168.217.134  netmask 255.255.255.0  broadcast 192.168.217.255        inet6 fe80::d7cc:dd17:7991:6c64  prefixlen 64  scopeid 0x20        ether 00:0c:29:03:62:63  txqueuelen 1000  (Ethernet)        RX packets 3455  bytes 248841 (243.0 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 637  bytes 54026 (52.7 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73  mtu 65536        inet 127.0.0.1  netmask 255.0.0.0        inet6 ::1  prefixlen 128  scopeid 0x10        loop  txqueuelen 1  (Local Loopback)        RX packets 68  bytes 5908 (5.7 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 68  bytes 5908 (5.7 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

• 修改 IP 地址

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33TYPE=\"Ethernet\"BOOTPROTO=\"static\"#把 DHCP 修改成 staticDEFROUTE=\"yes\"PEERDNS=\"yes\"PEERROUTES=\"yes\"IPV4_FAILURE_FATAL=\"no\"NAME=\"ens33\"UUID=\"8c7abe35-e956-4d21-bed2-31a92cbd17ea\"DEVICE=\"ens33\"ONBOOT=\"yes\"#网卡状态 IPADDR=192.168.0.230 #静态 IP  GATEWAY=192.168.0.1 #默认网关  NETMASK=255.255.255.0 #子网掩码  DNS1=192.168.0.1 #DNS 配置  

• 修改 DNS

[root@1234 ~]# vi /etc/resolv.conf# Generated by NetworkManager# No nameservers found; try putting DNS servers into your# ifcfg files in /etc/sysconfig/network-scripts like so:## DNS1=xxx.xxx.xxx.xxx# DNS2=xxx.xxx.xxx.xxx# DOMAIN=lab.foo.com bar.foo.comnameserver 202.198.98.167     #修改为当地运营商的 DNS 地址 nameserver 8.8.8.8

• 修改网关

[root@centos]# vi /etc/sysconfig/networkNETWORKING=yes         HOSTNAME=1234         #主机名 GATEWAY=172.18.1.254   #网关地址

• 配置静态路由(根据需要配置)

– 查看路由表

 [root@centos7 ~]# ip route showdefault via 192.168.150.254 dev enp0s3  proto static  metric 1024192.168.150.0/24 dev enp0s3  proto kernel  scope link  src 192.168.150.110  

– 添加静态路由

 [root@centos7 ~]# vi /etc/sysconfig/network-scripts/route-ens3310.15.150.0/24 via 192.168.150.253 dev enp0s310.25.250.0/24 via 192.168.150.253 dev enp0s3

• 重启网络

[root@centos7 ~]# systemctl restart network


本站部分文章来自网络或用户投稿,如无特殊说明或标注,均为本站原创发布。涉及资源下载的,本站旨在共享仅供大家学习与参考,如您想商用请获取官网版权,如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
科技百科

vivo手机忘记密码怎么办(vivo手机账号密码忘了怎么办)

2023-6-22 16:29:52

科技百科

三防手机哪一款最好(三防手机如何选择)

2023-6-22 16:30:31

搜索