ใช้คำสั่ง lxc 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 | sarankon@ubuntu:~$ lxc network Description: Manage and attach containers to networks Usage: lxc network [ command ] Available Commands: attach Attach network interfaces to containers attach-profile Attach network interfaces to profiles create Create new networks delete Delete networks detach Detach network interfaces from containers detach-profile Detach network interfaces from profiles edit Edit network configurations as YAML get Get values for network configuration keys list List available networks list-leases List DHCP leases rename Rename networks set Set network configuration keys show Show network configurations unset Unset network configuration keys Global Flags: --debug Show all debug messages --force- local Force using the local unix socket -h, --help Print help - v , --verbose Show all information messages --version Print version number Use "lxc network [command] --help" for more information about a command . |
แนะนำ 3 คำสั่งแรกที่เราจะได้ใช้งานคือ list, show และ set
lxc network list ใช้เมื่อต้องการแสดงข้อมูล network ของ host1 2 3 4 5 6 7 8 | sarankon@ubuntu:~$ lxc network list +--------+----------+---------+-------------+---------+ | NAME | TYPE | MANAGED | DESCRIPTION | USED BY | +--------+----------+---------+-------------+---------+ | enp0s3 | physical | NO | | 0 | +--------+----------+---------+-------------+---------+ | lxdbr0 | bridge | YES | | 0 | +--------+----------+---------+-------------+---------+ |
lxc network show [network-name] ใช้เมื่อต้องการดู Configuration ของ Network นั้น
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | sarankon@ubuntu:~$ lxc network show lxdbr0 config: ipv4.address: 10.24.200.1 /24 ipv4.nat: "true" ipv6.address: fd42:6cc:7629:65ea::1 /64 ipv6.nat: "true" description: "" name: lxdbr0 type : bridge used_by: [] managed: true status: Created locations: - none |
lxc network set [network-name] [key] [value] ใช้เมื่อต้องการแก้ไขค่า Configuration /ข้อมูลอ้างอิง Container Network
ตัวอย่างนี้ จะทำการเปลี่ยนวง IPv4 เป็น 10.10.10.1/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | sarankon@ubuntu:~$ lxc network set lxdbr0 ipv4.address 10.10.10.1 /24 sarankon@ubuntu:~$ lxc network show lxdbr0 config: ipv4.address: 10.10.10.1 /24 ipv4.nat: "true" ipv6.address: fd42:6cc:7629:65ea::1 /64 ipv6.nat: "true" description: "" name: lxdbr0 type : bridge used_by: [] managed: true status: Created locations: - none |
สร้าง Network เอง
ตัวอย่างการ Config เพื่อใช้งาน IPv4 และไม่ใช้งาน IPv61 2 | lxc network create lxdbr1 ipv4.address=172.168.0.1 /24 ipv4.nat= true ipv6.address=none ipv6.nat= false 6 |
ตัวอย่างการ Config IPv6 เมื่อไม่ต้องการใช้งาน
1 2 | lxc network set lxdbr1 ipv6.address none lxc network set lxdbr1 ipv6.nat false |
การ Set Static IP ให้กับ Container
ตัวอย่างนี้ เราจะต้องทำการหยุดการทำงานของ Container ก่อนจากนั้นก็ทำการ เพื่อ Network Interface เข้าไปเสร็จแล้วให้ไป Config Device กำหนด IP ผ่าน Network Interface ที่เพิ่มไปข้างต้น / ข้อมูลอ้างอิง Discuss Linux Container
1 2 3 4 5 6 7 8 9 | lxc stop ubuntu-container # lxc network attach <network name> <container name> <device name> <interface name> lxc network attach lxdbr0 ubuntu-container eth0 eth0 # lxc config device set <container name> <device name> <key> <value> lxc config device set ubuntu-container eth0 ipv4.address 10.10.10.10 lxc start ubuntu-container |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น