欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(YDW)Ubuntu下静态配网

程序员文章站 2024-03-25 18:16:34
...

1、ifconfig查看状态

aaa@qq.com:~/yudw2018$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:12:ea:0e  
          inet6 addr: fe80::20c:29ff:fe12:ea0e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:360 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:25731 (25.7 KB)  TX bytes:32112 (32.1 KB)
          Interrupt:19 Base address:0x2000 

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:16436  Metric:1
          RX packets:500 errors:0 dropped:0 overruns:0 frame:0
          TX packets:500 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:38708 (38.7 KB)  TX bytes:38708 (38.7 KB)

aaa@qq.com:~/yudw2018$ 

  eth0:第一块有线网卡
        sudo ifconfig eth0  down  关闭网卡
        sudo ifconfig eth0  up    开启网卡

2、添加ip地址,子网掩码,网关

aaa@qq.com:~/yudw2018$ sudo vi /etc/network/interfaces 
  1 auto lo
  2 iface lo inet loopback
  3 
  4 
  5 auto eth0
  6 
  7 #动态分配
  8 #iface eth0 inet dhcp
  9 #=====================
 10 
 11 #静态指定ip地址
 12 iface eth0 inet static
 13 address 192.168.5.105
 14 netmask 255.255.255.0                                                                                            
 15 gateway 192.168.5.1
 16 

 

3、设置域名解析器

aaa@qq.com:~/yudw2018$ sudo vi /etc/resolv.conf 
  1 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
  2 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
  3 
  4 nameserver 8.8.8.8                                                                                               
  5 

4、设置开机自运行脚本

aaa@qq.com:~/yudw2018$ sudo vi /etc/rc.local

  1 #!/bin/sh -e
  2 #
  3 # rc.local
  4 #
  5 # This script is executed at the end of each multiuser runlevel.
  6 # Make sure that the script will "exit 0" on success or any other
  7 # value on error.
  8 #
  9 # In order to enable or disable this script just change the execution
 10 # bits.
 11 #
 12 # By default this script does nothing.
 13 
 14 echo "nameserver 8.8.8.8" >> /etc/resolv.conf                                                                    
 15 
 16 exit 0
 17 

5、重启网络设备

aaa@qq.com:~/yudw2018$ sudo /etc/init.d/networking restart 
 * Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
 * Reconfiguring network interfaces...                                                                        [ OK ] 
aaa@qq.com:~/yudw2018$ 

6、测试

aaa@qq.com:~/yudw2018$ ping www.baidu.com
PING www.a.shifen.com (119.75.213.61) 56(84) bytes of data.
64 bytes from 119.75.213.61: icmp_req=1 ttl=56 time=54.7 ms
64 bytes from 119.75.213.61: icmp_req=2 ttl=56 time=68.4 ms
64 bytes from 119.75.213.61: icmp_req=3 ttl=56 time=59.7 ms
^C64 bytes from 119.75.213.61: icmp_req=4 ttl=56 time=76.5 ms

--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 15310ms
rtt min/avg/max/mdev = 54.776/64.896/76.595/8.348 ms
aaa@qq.com:~/yudw2018$ 

ping www.baidu.com出现以上情形证明成功。

7、如果还不好使,检查虚拟机网卡配置;手动设置ip

(YDW)Ubuntu下静态配网        (YDW)Ubuntu下静态配网