美文网首页
Ubuntu / Kali / CentOS: 网络配置

Ubuntu / Kali / CentOS: 网络配置

作者: 捞小虾 | 来源:发表于2018-05-07 11:14 被阅读57次

    Author: Xu FC

    Ubuntu 网络配置


    • OS: Ubuntu 16.04.1
    • IP地址、默认网关、静态路由 和 dns-namesevers 配置: vi /etc/network/interfaces
    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    
    auto ens32
    iface ens32 inet static
    address 172.16.77.63
    netmask 255.255.255.0
    broadcase 172.16.77.255
    
    auto ens33
    iface ens33 inet static
    address 178.1.1.61
    netmask 255.255.255.0
    broadcase 178.1.1.255
    
    gateway 172.16.77.1
    up route add -net 179.1.1.0 netmask 255.255.255.0 gw 178.1.1.1 dev ens33
    down route del -net 179.1.1.0 netmask 255.255.255.0 gw 178.1.1.1 dev ens33
    
    dns-nameservers 192.168.80.10
    
    • 重启系统: reboot

    • 查看IP地址: ip add

    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:15:ee:af brd ff:ff:ff:ff:ff:ff
        inet 172.16.77.63/24 brd 172.16.77.255 scope global ens32
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe15:eeaf/64 scope link 
           valid_lft forever preferred_lft forever
    3: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:15:ee:b9 brd ff:ff:ff:ff:ff:ff
        inet 179.1.1.63/24 brd 179.1.1.255 scope global ens33
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:fe15:eeb9/64 scope link 
           valid_lft forever preferred_lft forever
    4: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:15:ee:c3 brd ff:ff:ff:ff:ff:ff
    5: ens35: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:15:ee:cd brd ff:ff:ff:ff:ff:ff
    root@ads_test_server_1:/home/test# 
    
    • 查看路由: ip route
    default via 172.16.77.1 dev ens32 onlink 
    169.254.0.0/16 dev ens32  scope link  metric 1000 
    172.16.77.0/24 dev ens32  proto kernel  scope link  src 172.16.77.61 
    178.1.1.0/24 dev ens33  proto kernel  scope link  src 178.1.1.61 
    179.1.1.0/24 via 178.1.1.1 dev ens33 
    
    • 查看 DNS server: nslookup
    root@ads_test_server_1:/home/test# nslookup
    > server
    Default server: 192.168.80.10
    Address: 192.168.80.10#53
    > 
    

    Kali 网络配置


    • OS: Linux server2 4.15.0-kali2-amd64 #1 SMP Debian 4.15.11-1kali1 (2018-03-21) x86_64 GNU/Linux
    IP地址、默认网关、静态路由 配置
    • 编辑 interfaces 配置文件: vi /etc/network/interfaces
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    auto eth1
    iface eth1 inet static
    address 172.16.2.22
    netmask 255.255.255.0
    broadcase 172.16.2.255
    gateway 172.16.2.1
    
    auto eth0
    iface eth0 inet static
    address 179.2.1.22
    netmask 255.255.255.0
    broadcase 179.2.1.255
    
    up route add -net 178.2.1.0 netmask 255.255.255.0 gw 179.2.1.1 dev eth0
    down route del -net 178.2.1.0 netmask 255.255.255.0 gw 179.2.1.1 dev eth0
    
    • 重启: reboot
    • 查看 IP地址: ip add
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:b9:ab:81 brd ff:ff:ff:ff:ff:ff
        inet 179.2.1.22/24 brd 179.2.1.255 scope global eth0
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:feb9:ab81/64 scope link 
           valid_lft forever preferred_lft forever
    3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 00:0c:29:b9:ab:8b brd ff:ff:ff:ff:ff:ff
        inet 172.16.2.22/24 brd 172.16.2.255 scope global eth1
           valid_lft forever preferred_lft forever
        inet6 fe80::20c:29ff:feb9:ab8b/64 scope link 
           valid_lft forever preferred_lft forever
    
    • 查看路由: ip route
    default via 172.16.2.1 dev eth1 onlink 
    172.16.2.0/24 dev eth1 proto kernel scope link src 172.16.2.22 
    178.2.1.0/24 via 179.2.1.1 dev eth0 
    179.2.1.0/24 dev eth0 proto kernel scope link src 179.2.1.22 
    
    dns-nameservers 配置
    • dns-nameservers 配置: vi /etc/resolv.conf
    nameserver 192.168.80.10
    
    • 重启: reboot
    • 查看 nameserver 是否配置成功
    root@server2:~# nslookup
    > server
    Default server: 192.168.80.10
    Address: 192.168.80.10#53
    

    CentOS 网络配置


    • OS: CentOS Linux 7 (Core)
    IP地址配置 和 默认网关 配置
    • 查看 interface name: ip add
    • 编辑相应 interface 的 ifcfg 文件 ifcfg-interface-name: vi /etc/sysconfig/network-scripts/ifcfg-ens256
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=static
    IPADDR=172.16.2.17
    NETMASK=255.255.255.0
    GATEWAY=172.16.2.1
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=ens256
    UUID=e09ba4bf-441c-4d7d-a518-fc9be7af6083
    DEVICE=ens256
    ONBOOT=yes
    
    • 重启 network 服务: /etc/init.d/network restart
    • 查看 IP 地址: ip address show ens256
    4: ens256: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
        link/ether 00:0c:29:b5:cc:4d brd ff:ff:ff:ff:ff:ff
        inet 172.16.2.17/24 brd 172.16.2.255 scope global ens256
           valid_lft forever preferred_lft forever
        inet6 fe80::3a02:56a6:59e4:a7a0/64 scope link 
           valid_lft forever preferred_lft forever
    
    • 查看默认网关: ip route
    default via 172.16.2.1 dev ens256 proto static metric 100 
    172.16.2.0/24 dev ens256 proto kernel scope link src 172.16.2.17 metric 100 
    
    静态路由配置
    • 查看 interface name: ip add
    • 编辑相应 interface 的 route 文件 route-interface-name: vi /etc/sysconfig/network-scripts/route-ens256
    10.0.0.0/8 via 172.16.2.1 dev ens256
    
    • 重启: reboot
    • 查看路由: ip route
    10.0.0.0/8 via 172.16.2.1 dev ens256 proto static metric 100 
    
    dns-namesevers 配置
    • dns-nameservers 配置: vi /etc/resolv.conf
    nameserver 192.168.80.10
    
    • 重启: reboot
    • 查看 nameserver 是否配置成功
    [root@localhost etc]# ping baidu.com
    PING baidu.com (220.181.57.216) 56(84) bytes of data.
    64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=49 time=6.27 ms
    64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=49 time=7.19 ms
    

    相关文章

      网友评论

          本文标题:Ubuntu / Kali / CentOS: 网络配置

          本文链接:https://www.haomeiwen.com/subject/xnhmrftx.html