WebUI for tcconfig which wraps TC(Linux Traffic Control)
![tcui](https://private-user-images.githubusercontent.com/2777660/266205663-91fb5051-6ace-4c3e-9364-1a2a526be62b.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTY2ODIyNTMsIm5iZiI6MTcxNjY4MTk1MywicGF0aCI6Ii8yNzc3NjYwLzI2NjIwNTY2My05MWZiNTA1MS02YWNlLTRjM2UtOTM2NC0xYTJhNTI2YmU2MmIuanBnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDUyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA1MjZUMDAwNTUzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OGY5YzM4MGZkYTJjMTVjMzgwN2JhZTk1YWQ2OTE2MWU3ODhkMzViNjMzYjFmMzYzYmUwMzEwMjU1NzI3MjI0YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.QCMST8rKJN93ff6CaGFFFpnAVugskXfpnG5U-kyb-J0)
Ensure there is ifb.ko
on your server:
ls /lib/modules/$(uname -r)/kernel/drivers/net/ifb.ko 2>/dev/null && echo yes || echo no
Run TC WebUI by docker:
docker run --network=host --privileged -it --restart always -d \
--name tc -v /lib/modules:/lib/modules:ro ossrs/tc-ui:1
Note: Only support Linux server, because it requires kernel module ifb and host network mode.
Note: Please use
registry.cn-hangzhou.aliyuncs.com/ossrs/tc-ui:1
in China.
Open http://localhost:2023 in browser.
If want to export the docker image:
docker pull ossrs/tc-ui:1
docker save ossrs/tc-ui:1 |gzip > tc-ui.tar.gz
If want to download the arm64 docker image:
docker pull --platform linux/arm64 ossrs/tc-ui:1
docker save ossrs/tc-ui:1 |gzip > tc-ui.tar.gz
Load the docker image:
docker load -i tc-ui.tar.gz
There is an HTTP OpenAPI, pass cmd in HTTP POST body, for example:
curl http://localhost:2023/tc/api/v1/config/raw -X POST -d 'tcshow lo'
Set 10% loss of interface lo:
curl http://localhost:2023/tc/api/v1/config/raw -X POST -d 'tcset lo --loss 10%'
#{"code":0,"data":null}
Get settings of interface lo:
curl http://localhost:2023/tc/api/v1/config/raw -X POST -d 'tcshow lo'
#{"code":0,"data":{"lo":{"incoming":{},"outgoing":{}}}}
Reset all settings of interface lo:
curl http://localhost:2023/tc/api/v1/config/raw -X POST -d 'tcdel --all lo'
#{"code":0,"data":null}
Only allow tcset
, tcshow
and tcdel
, or failed:
curl http://localhost:2023/tc/api/v1/config/raw -X POST -d 'ls'
#{"code":100,"data":"invalid cmd ls"}
For TC command, see:
- Set traffic control (tcset command)
- Delete traffic control (tcdel command)
- Display traffic control configurations (tcshow command)
Run Go API server in Ubuntu20 server or docker:
docker build -t test -f Dockerfile.dev .
docker run --privileged --rm -it -p 2023:2023 -v $(pwd):/g -w /g test go run .
Note: Note that macOS docker doesn't support ingress, which requires kernel module ifb.
Note: Must run with
--privileged
or failed to runtc
andtcpdump
commands.
Build UI:
(cd ui && npm install && npm run build)
# Or
(cd ui && npm install && npm run start)
Open http://localhost:3000/ in browser.
Please install required tools, for Ubuntu20:
apt-get update -y
apt-get install -y curl tcpdump iputils-ping iproute2
curl -L https://golang.google.cn/dl/go1.16.12.linux-amd64.tar.gz |tar -xz -C /usr/local
export PATH=$PATH:/usr/local/go/bin
Please install tc and tcpdump:
sudo apt-get install -y iproute2 tcpdump
You can verify the installation by tc qdisc help
and tcpdump --version
.
Please install tcconfig:
# For Ubuntu20
sudo apt-get install -y python3-pip
sudo pip install tcconfig
# For CentOS7
sudo yum install -y python3-pip
sudo pip3 install tcconfig
You can verfiy the installation by tcset --version
.
Please install Go 1.16+ by yourself and verfiy the installation by go version
.
This is optional for docker.
Config by environment variables, so create a .env
file with:
API_HOST=ubuntu20
API_LISTEN=2023
UI_HOST=localhost
UI_PORT=3001
NODE_ENV=development
IFACE_FILTER_IPV4=true
IFACE_FILTER_IPV6=true
This is optional.