您尚未登录。

#1 2016-12-08 19:26:51

roadgo
会员
注册时间: 2012-04-07
帖子: 380

无线网卡下使用lxc

安装lxc和 arch-install-scripts

$ lxc-checkconfig
我的如下:
--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: missing
Network namespace: enabled

--- Control groups ---
Cgroup: enabled
Cgroup clone_children flag: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
Bridges: enabled
Advanced netfilter: enabled
CONFIG_NF_NAT_IPV4: enabled
CONFIG_NF_NAT_IPV6: enabled
CONFIG_IP_NF_TARGET_MASQUERADE: enabled
CONFIG_IP6_NF_TARGET_MASQUERADE: enabled
CONFIG_NETFILTER_XT_TARGET_CHECKSUM: enabled
FUSE (for use with lxcfs): enabled

--- Checkpoint/Restore ---
checkpoint restore: missing
CONFIG_FHANDLE: enabled
CONFIG_EVENTFD: enabled
CONFIG_EPOLL: enabled
CONFIG_UNIX_DIAG: enabled
CONFIG_INET_DIAG: enabled
CONFIG_PACKET_DIAG: enabled
CONFIG_NETLINK_DIAG: enabled
File capabilities: enabled

Note : Before booting a new kernel, you can check its configuration
usage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig
设置网络:(我用的是无线)
#cp /etc/netctl/examples/bridge  /etc/netctl/lxcbridge

/etc/netctl/lxcbridge

Description="LXC bridge"
Interface=br0
Connection=bridge
IP=static
Address=192.168.2.111/24
说明:第二行为网桥,我取的名字为br0。如果试了不行可用以下命令建一个# brctl addbr bridge_name(网桥名)
把网桥用起来:
# netctl switch-to lxcbridge
# netctl enable lxcbridge
开启nat转发
# iptables -t nat -A POSTROUTING -o wlp3s0 -j MASQUERADE(wlp3s0为你的无线网卡名)
ping一下,网络通不?
$ ping -c 1 www.baidu.com
创建一个名为playtime的archlinux(可自行根据你要的linux选择模版)
# lxc-create -n playtime -t /usr/share/lxc/templates/lxc-archlinux
修改playtime有网络配置:
/var/lib/lxc/playtime/config
lxc.network.link = br0这行改成你的网桥名
lxc.network.ipv4 = 192.168.2.112/24这行改成你的playtime的ip
lxc.network.ipv4.gateway = 192.168.2.105这行改成你真机的ip当网关。
启用系统
# lxc-console -n playtime
出现登录不了
login: root
Login incorrect
另开一个终端
# lxc-attach -n playtime
[root@playtime]# useradd -m -G wheel newuser(新用户名)
[root@playtime]# passwd newuser
[root@playtime]# passwd root
[root@playtime]# exit
# lxc-console -n playtime
[newuser@playtime]$ su
好了,可以用了

离线

页脚