linux下修改IP地址

查看IP

ifconfig

[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 52:54:00:8a:fe:e6  txqueuelen 1000  (Ethernet)
        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

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.69  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::a00:27ff:fe94:9b6c  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:94:9b:6c  txqueuelen 1000  (Ethernet)
        RX packets 737  bytes 75483 (73.7 KiB)
        RX errors 0  dropped 2  overruns 0  frame 0
        TX packets 114  bytes 12081 (11.7 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
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 68  bytes 5912 (5.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 68  bytes 5912 (5.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这里修改 eth1
inet 192.168.10.69 id地址
netmask 255.255.255.0子网掩码
broadcast 192.168.10.255广播地址

修改eth1

  • 进入 /etc/sysconfig/network-scripts/
  • 执行ls
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0   ifdown-ippp    ifdown-sit       ifup-bnep  ifup-plusb   ifup-TeamPort
ifcfg-eth1   ifdown-ipv6    ifdown-Team      ifup-eth   ifup-post    ifup-tunnel
ifcfg-lo     ifdown-isdn    ifdown-TeamPort  ifup-ippp  ifup-ppp     ifup-wireless
ifdown       ifdown-post    ifdown-tunnel    ifup-ipv6  ifup-routes  init.ipv6-global
ifdown-bnep  ifdown-ppp     ifup             ifup-isdn  ifup-sit     network-functions
ifdown-eth   ifdown-routes  ifup-aliases     ifup-plip  ifup-Team    network-functions-ipv6
  • 打开配置文件
[root@localhost network-scripts]# vim ifcfg-eth1 
#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
BOOTPROTO=static  #dhcp 动态获取IP  static 静态IP
#dhcp
ONBOOT=yes
DEVICE=eth1
NM_CONTROLLED=yes
DNS1=114.114.114.114  #DNS解析
IPADDR=192.168.10.69 #IP地址
NETMASK=255.255.255.0 #子网掩码
GATEWAY=192.168.10.1 #网关
#VAGRANT-END
  • wq保存退出
  • 重启网络配置

1.在终端输入:/etc/init.d/networ restart;
2.ifdown eth0 & ifup eth0;
3.ifconfig eth0 down & ifconfig eth0 up
备注:eth0是网卡的名字

  • reboot 重启linux
[root@localhost network-scripts]# reboot
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。