0%

pve搭建lxc openwrt并直通网卡

直通pve的物理网卡给openwrt lxc,用于拨号等操作!

搭建openwrt lxc

直接命令创建lxc容器,不传递网卡参数

1
2
3
4
5
6
7
8
pct create 119 local:vztmpl/openwrt-23.05.4-x86-64-rootfs.tar.gz \
--rootfs local-lvm:8 \
--ostype unmanaged \
--hostname openwrt \
--arch amd64 \
--cores 4 \
--memory 1024 \
--swap 0

修改lxc配置文件

1
nano /etc/pve/lxc/119.conf

增加直通网卡及pppoe拨号设备和tun设备,直通网卡的指令顺序不能乱,否则启动openwrt失败或者会导致name参数不传递!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 第一个直通网卡
lxc.net.0.type: phys
lxc.net.0.link: enp2s0
lxc.net.0.name: eth0
lxc.net.0.flags: up
# 第二个直通网卡
lxc.net.1.type: phys
lxc.net.1.link: enp3s0
lxc.net.1.name: eth1
lxc.net.1.flags: up
# pve自带的openwrt基础组件配置
lxc.include: /usr/share/lxc/config/openwrt.common.conf
# 挂载ppp设备,用于pppoe拨号
lxc.cgroup2.devices.allow: c 108:0 rwm
lxc.mount.entry: /dev/ppp dev/ppp none bind,create=file
# 挂载tun设备
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file

openwrt简单配置

修改网络配置文件

1
vi /etc/init.d/network

主路由拨号设置方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option ula_prefix 'fd55:5742:661c::/48'

config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'

config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.2.1' # lan静态IP
option netmask '255.255.255.0' # 子网掩码
option ip6assign '60'
option defaultroute '0'

config interface 'wan'
option proto 'pppoe'
option device 'eth1'
option username 'aaaa' # pppoe拨号账户
option password 'bbbb' # pppoe拨号密码
option ipv6 'auto'

config interface 'wan6'
option device 'eth1'
option proto 'dhcpv6'

旁路由设置方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option ula_prefix 'fd55:5742:661c::/48'

config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'

config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.2.119' # lan静态IP
option netmask '255.255.255.0' # 子网掩码
option ip6assign '60'
option gateway '192.168.2.103' # 网关
list dns '192.168.2.105' # DNS

旁路由需要配置网关,dns,并且删除dhcp配置文件,否则无法联网

1
mv /etc/config/dhcp /etc/config/dhcp.bak

此命令只是将其重命名了,以后如果需要的话再重命名回来即可

1
mv /etc/config/dhcp.bak /etc/config/dhcp

重启openwrt

1
reboot

因为openwrt官方rootfs太过精简,所以需要下载中文字体及一些必要程序

1
2
opkg update
opkg install vim curl luci-i18n-base-zh-cn luci-i18n-firewall-zh-cn luci-i18n-opkg-zh-cn

现在可插上网线进入openwrt web页面!