Browse Source

Update Docker

pull/15/head
Jason 5 years ago
parent
commit
52478f056e
  1. 28
      Dockerfile
  2. 41
      tun2socks.sh

28
Dockerfile

@ -3,16 +3,30 @@ FROM golang:alpine as builder
WORKDIR /tun2socks-src
COPY . /tun2socks-src
RUN apk add --no-cache \
git \
make \
gcc \
musl-dev \
RUN apk add --update --no-cache \
gcc git make musl-dev \
&& go mod download \
&& make build \
&& mv ./bin/tun2socks /tun2socks
FROM alpine:latest
COPY --from=builder /tun2socks /
ENTRYPOINT ["/tun2socks"]
COPY ./tun2socks.sh /
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

@ -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
Loading…
Cancel
Save