以太网接口可以分为IP模式和桥接模式,在IP模式下就得先有一个IP地址,以太网接口获取IP地址的方法,我知道的有三种:StaticDHCPPPPoE。如下例子中使用的eth4WAN Ethernet的接口名字

  • 通过ifconfig命令配置接口的IP地址192.168.88.15/24、网关地址192.168.88.1DNS地址1.1.1.2,1.1.1.7MAC地址F6:D9:53:7B:C4:1DMTU1490

ifconfig eth4 0.0.0.0

ifconfig eth4 down

ifconfig eth4 mtu 1490

ifconfig eth4 hw ether F6:D9:53:7B:C4:1D

ifconfig eth4 192.168.88.15 netmask 255.255.255.0

ifconfig eth4 up

  • 写入DNS值到文件/etc/resolv.conf

# cat /etc/resolv.conf

nameserver 1.1.1.2

nameserver 1.1.1.7

  • 添加route网络

route del -net 192.168.88.0 netmask 255.255.255.0 eth4

route add -net 192.168.88.0 netmask 255.255.255.0 eth4

  • 如果以eth4作为默认路由,则为它建立默认路由规则

route del default gw 192.168.88.1 dev eth4

route add default gw 192.168.88.1 dev eth4

  • 启动dns relay相关进程dnsmasq,配置中br0LAN Ethernet,而listen-address是指br0IP地址。

# dnsmasq -C /var/dnsmasq.conf

# cat /var/dnsmasq.conf

no-resolv

no-dhcp-interface=br0

listen-address=192.168.1.1

server=1.1.1.2

server=1.1.1.7

DHCP

以太网接口可以通过busybox自带的udhcpc进程获取动态IP地址,其框架是:可执行文件udhcpc、脚本文件/etc/default.scriptDNS配置文件/etc/resolv.conf

  • udhcpc的部分参数说明
-i,--interface IFACE    Interface to use (default eth0)
-p,--pidfile FILE       Create pidfile
-s,--script PROG      Run PROG at DHCP events (default /etc/default.script)
  • 脚本/etc/default.script的内容大致如下
 1 #!/bin/sh
 2 # udhcpc script edited by Tim Riker <Tim@Rikers.org>
 3 [ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
 4 RESOLV_CONF="/etc/resolv.conf"
 5 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
 6 [ -n "$subnet" ] && NETMASK="netmask $subnet"
 7 case "$1" in
 8     deconfig)
 9         if [ $? -eq 0 ]; then
10             /sbin/ifconfig $interface up
11         fi
12         if [ $? -eq 0 ]; then
13             /sbin/ifconfig $interface 0.0.0.0
14         fi;;
15     renew|bound)
16         /sbin/ifconfig $interface $ip $BROADCAST $NETMASK
17         if [ -n "$router" ] ; then
18             echo "deleting routers"
19             while route del default gw 0.0.0.0 dev $interface ; do
20                 :
21             done
22             for i in $router ; do
23                 route add default gw $i dev $interface
24             done
25         fi
26         echo -n > $RESOLV_CONF
27         [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
28         for i in $dns ; do
29             echo adding dns $i
30             echo nameserver $i >> $RESOLV_CONF
31         done
32         ;;
33 esac
34 exit 0
View Code

相关文章:

  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-05-06
  • 2022-01-10
  • 2022-01-25
猜你喜欢
  • 2021-11-01
  • 2021-07-27
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
相关资源
相似解决方案