3分鍾Ubuntu系統下配置靜態IP和DHCP服務


安裝DHCP服務:sudo apt install isc-dhcp-server

打開相應防火牆:

sudo iptables -I INPUT -p tcp --dport 8080:8084 -j ACCEPT

sudo iptables -I INPUT -p udp --dport 69 -j ACCEPT


配置如下:

if everything is okay,your DUT can get IP from SERVER DHCP, and 'ping 101.1.2.4' is good.
and 'ifconfig' should be like this:
     "<eth1>  inet addr:101.1.2.4  Bcast:101.1.255.255  Mask:255.255.0.0"

Question:
1. How to match the real network card hardware with it's name?
      ethtool -p <eth0>  #the relative network card hardware will blinky.

2. How to config the static IP on server?  ( in directory: /etc/network/interfaces )

          # 配置網卡1,作為連接后端server的網卡與其靜態IP (若無則不需要配置)
         # config the static IP to connect backend server
         auto eth1
         iface eth1 inet static
             address 192.168.253.85  #should be changed with different server/network card
             netmask 255.255.255.0
             gateway 192.168.253.1
        
         ##配置網卡2,作為服務器的網卡與其靜態IP
         auto p2p1   #不要忘記在 /etc/default/isc-dhcp-server 中配置默認的DHCP服務網卡!
         iface p2p1 inet static
             address 101.1.2.4
             netmask 255.255.0.0

        #配置網卡3,作為連接互聯網的網卡與其靜態IP (若無則不需配置)
         auto eth4
         iface eth4 inet static
             address 10.240.16.37     #click the wired connection info
             netmask 255.255.255.0
             gateway 10.240.16.250  #ip route | grep default
             dns-nameserver 8.8.8.8

Note: [Important]Connect Internet will cause conflict, so you can just choose one way in one time                      
use cmd to verify, cmd: sudo /etc/init.d/networking restart

這里靜態IP已經固定完成,可用 ifconfig 檢查對應網口的IP是否正確

3. How to config the  Bcast IP/the Mask IP?  ( in directory: /etc/dhcp/dhcpd.conf )       

          subnet 101.1.0.0 netmask 255.255.0.0 {
              range 101.1.5.10 101.1.200.255;     #配置ip范圍
              option domain-name-servers 101.1.2.1;
              option domain-name "example.org";
              option broadcast-address 101.1.255.255;
              option routers 101.1.2.4;
              option subnet-mask 255.255.0.0;
              # filename "vmlinux.bin";
              # option dhcp-server-identifier 101.1.2.4;
              next-server 101.1.2.4;
         }

       host mydhcp {

           hardware ethernet 00:0e:c6:fb:4b:8b; #(物理地址替換為你查到的)

          fixed-address 101.1.2.4;

       }

verify cmd:

sudo service networking restart; sudo service isc-dhcp-server restart && sudo reboot

sudo netstat –uap #檢查DHCP服務是否正常進行

/var/log/syslog #查看系統log,定位配置問題


重啟network-manager 服務

# service network-manager restart

# systemctl disable NetworkManager.service

# systemctl enable NetworkManager.service


其他
pci設備的網卡
         lspci -v
激活網卡
         sudo ifconfig 網卡設備名 up
查詢USB網口
         lsusb


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM