mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-31 03:56:30 +08:00
Update Docker
This commit is contained in:
28
Dockerfile
28
Dockerfile
@@ -3,16 +3,30 @@ FROM golang:alpine as builder
|
|||||||
WORKDIR /tun2socks-src
|
WORKDIR /tun2socks-src
|
||||||
COPY . /tun2socks-src
|
COPY . /tun2socks-src
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --update --no-cache \
|
||||||
git \
|
gcc git make musl-dev \
|
||||||
make \
|
|
||||||
gcc \
|
|
||||||
musl-dev \
|
|
||||||
&& go mod download \
|
&& go mod download \
|
||||||
&& make build \
|
&& make build \
|
||||||
&& mv ./bin/tun2socks /tun2socks
|
&& mv ./bin/tun2socks /tun2socks
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
COPY --from=builder /tun2socks /
|
COPY ./tun2socks.sh /
|
||||||
ENTRYPOINT ["/tun2socks"]
|
COPY --from=builder /tun2socks /usr/local/bin
|
||||||
|
|
||||||
|
RUN apk add --update --no-cache \
|
||||||
|
curl lsof iptables iproute2 bind-tools \
|
||||||
|
&& chmod +x /tun2socks.sh
|
||||||
|
|
||||||
|
ENV TUN tun0
|
||||||
|
ENV ETH eth0
|
||||||
|
ENV ETHGW 172.16.1.1
|
||||||
|
ENV TUNGW 240.0.0.1
|
||||||
|
ENV PROXY 172.16.1.2:1080
|
||||||
|
ENV MONITOR 0.0.0.0:80
|
||||||
|
ENV EXCLUDED 172.16.1.2/32
|
||||||
|
ENV LOGLEVEL warning
|
||||||
|
ENV BACKENDDNS 8.8.8.8:53
|
||||||
|
ENV HOSTS localhost=127.0.0.1
|
||||||
|
|
||||||
|
ENTRYPOINT ["/tun2socks.sh"]
|
||||||
|
|||||||
41
tun2socks.sh
Normal file
41
tun2socks.sh
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
TUN="${TUN:-utun0}"
|
||||||
|
ETH="${ETH:-eth0}"
|
||||||
|
ETHGW="${ETHGW:-172.16.1.1}"
|
||||||
|
TUNGW="${TUNGW:-240.0.0.1}"
|
||||||
|
PROXY="${PROXY:-172.16.1.2:1080}"
|
||||||
|
MONITOR="${MONITOR:-0.0.0.0:80}"
|
||||||
|
EXCLUDED="${EXCLUDED:-172.16.1.2/32}"
|
||||||
|
LOGLEVEL="${LOGLEVEL:-warning}"
|
||||||
|
BACKENDDNS="${BACKENDDNS:-8.8.8.8:53}"
|
||||||
|
HOSTS="${HOSTS:-localhost=127.0.0.1}"
|
||||||
|
|
||||||
|
# enable ip_forward
|
||||||
|
sysctl -w net.ipv4.ip_forward=1 &> /dev/null
|
||||||
|
|
||||||
|
# create tun device
|
||||||
|
ip tuntap add mode tun dev $TUN
|
||||||
|
ip addr add $TUNGW/24 dev $TUN
|
||||||
|
ip link set dev $TUN up
|
||||||
|
echo "tun device created: $TUN"
|
||||||
|
|
||||||
|
# change default gateway
|
||||||
|
ip route del default &> /dev/null
|
||||||
|
ip route add default via $TUNGW dev $TUN
|
||||||
|
|
||||||
|
# add to ip route
|
||||||
|
for ip in $(echo $EXCLUDED | tr ',' '\n')
|
||||||
|
do
|
||||||
|
ip route add $ip via $ETHGW
|
||||||
|
done
|
||||||
|
|
||||||
|
# DNS settings
|
||||||
|
echo "nameserver $TUNGW" > /etc/resolv.conf
|
||||||
|
echo "DNS settings updated"
|
||||||
|
|
||||||
|
tun2socks -loglevel $LOGLEVEL \
|
||||||
|
-tunName $TUN -proxyServer $PROXY \
|
||||||
|
-monitor -monitorAddr $MONITOR \
|
||||||
|
-fakeDNS -hosts $HOSTS \
|
||||||
|
-backendDNS $BACKENDDNS
|
||||||
Reference in New Issue
Block a user