//使用veth
//1.创建两块虚拟网卡veth1、veth2,然后点对点连接,此后两块网卡的数据会互相发送到对方
$ ip link add veth1 type veth peer name veth2
//2.创建网络命名空间t1
$ ip netns add t1
//3.将veth0加入t1,此时veth0便看不到了,因为被加入到其他命名空间中了
$ ip link set veth0 netns t1
//4.配置veth0的ip地址
$ ip netns exec t1 ifconfig eth0 192.168.1.200/24
//5.设置t1网络的默认路由
$ ip netns exec t1 route add default gw 192.168.1.1
//6.此时将veth2加入本地网桥中,便可以实现veth1在t1中访问外部网络了,过程略,可参考docker中的网络配置步骤
//veth的实现方法(drivers/net/veth.c)
//向ip link注册服务
1.1 static __init int veth_init(void)
{
return rtnl_link_register(&veth_link_ops);
}
//处理ip link命令
2.1 static struct rtnl_link_ops veth_link_ops = {
.kind = DRV_NAME,
.priv_size = sizeof(struct veth_priv),
.setup = veth_setup,
.validate = veth_validate,
.newlink = veth_newlink,
.dellink = veth_dellink,
.policy = veth_policy,
.maxtype = VETH_INFO_MAX,
};
//新加入一条veth链接
2.2 static int ve
网络子系统87_veth实现
最新推荐文章于 2023-02-24 10:42:48 发布