I don't get IP when I connect my pc to VLAN port

In my router, I have 3 ports and 1 wan port. I create three vlans 1,2,3 and I connect port 1 to vlan 1 , port 2 to vlan 2 , port 3 to vlan 3, then I create interfaces for each vlan and give each of them static IP, but when I connect my pc to ports I didn't get any ip address from router.

Any help please.


**config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd35:6bdc:dc2e::/48'

config atm-bridge 'atm'
        option vpi '1'
        option vci '32'
        option encaps 'llc'
        option payload 'bridged'
        option nameprefix 'dsl'

config dsl 'dsl'
        option annex 'a'
        option tone 'av'
        option ds_snr_offset '0'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0.1'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.100.240'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        list dns '1.1.1.1'
        option ip6assign '60'

config device
        option name 'dsl0'
        option macaddr 'e8:94:f6:0f:54:b3'

config interface 'wan'
        option device 'dsl0'
        option proto 'pppoe'
        option username 'username'
        option password 'password'
        option ipv6 '1'

config interface 'wan6'
        option device '@wan'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option vid '1'
        option ports '4 5 6t'

config device
        option name 'eth0'
        option mtu '1500'
        option macaddr 'E8:94:F6:0F:54:B5'
        option txqueuelen '1000'
        option ipv6 '0'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '0 6t'
        option vid '2'

config switch_vlan
        option device 'switch0'
        option vlan '3'
        option vid '3'
        option ports '2 6t'

config interface 'VLAN2'
        option proto 'static'
        option device 'eth0.2'
        option ipaddr '172.16.10.10'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        option broadcast '172.16.10.255'
        list dns '1.1.1.1'

config interface 'VLAN3'
        option proto 'static'
        option device 'eth0.3'
        option ipaddr '10.10.10.10'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        option broadcast '10.10.10.255'
        list dns '1.1.1.1'**

did you configure your client to use the corresponding VLAN ?

I only connect my pc directly to ports by ethernet cable. Is that enough ?

pretty sure it isn't ... but I'm not VLAN expert :frowning:
for fun, try removing the VLAN for one of the ports, see if it works then.

If remove vlan , then my pc will get IP from LAN, but i want it to get ip from vlan.

First of all, remove the gateway option from the vlan2 and vlan3 interfaces. Second it seems that you have not assigned the interfaces to any firewall zone.

Please run the following commands (copy-paste the whole block) and paste the output here, using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have

ubus call system board; \
uci export network; \
uci export dhcp; uci export firewall; \
head -n -0 /etc/firewall.user; \
ip -4 addr ; ip -4 ro li tab all ; ip -4 ru; \
ls -l  /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/* ; head -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*

you wouldn't do that unless you used a tagged VLAN on the port - which is not the case

did you set up DHCP for the VLAN interfaces?

static IP address.

root@OpenWrt:/# ubus call system board;
{
        "kernel": "5.4.143",
        "hostname": "OpenWrt",
        "system": "xRX200 rev 1.2",
        "model": "TP-LINK TD-W8970",
        "board_name": "tplink,tdw8970",
        "release": {
                "distribution": "OpenWrt",
                "version": "21.02.0",
                "revision": "r16279-5cc0535800",
                "target": "lantiq/xrx200",
                "description": "OpenWrt 21.02.0 r16279-5cc0535800"
        }
}
root@OpenWrt:/# uci export network
package network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd35:6bdc:dc2e::/48'

config atm-bridge 'atm'
        option vpi '1'
        option vci '32'
        option encaps 'llc'
        option payload 'bridged'
        option nameprefix 'dsl'

config dsl 'dsl'
        option annex 'a'
        option tone 'av'
        option ds_snr_offset '0'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0.1'

config interface 'lan'
        option proto 'static'
        option ipaddr '192.168.100.240'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        list dns '1.1.1.1'
        option ip6assign '60'
        option device 'eth0.1'

config device
        option name 'dsl0'
        option macaddr 'e8:94:f6:0f:54:b3'


config interface 'wan'
        option device 'dsl0'
        option proto 'pppoe'
        option username 'username'
        option password 'password'
        option ipv6 '1'

config interface 'wan6'
        option device '@wan'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option vid '1'
        option ports '4 5 6t'

config device
        option name 'eth0'
        option mtu '1500'
        option macaddr 'E8:94:F6:0F:54:B5'
        option txqueuelen '1000'
        option ipv6 '0'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '0 6t'
        option vid '2'

config switch_vlan
        option device 'switch0'
        option vlan '3'
        option vid '3'
        option ports '2 6t'

config interface 'VLAN2'
        option proto 'static'
        option device 'eth0.2'
        option ipaddr '172.16.10.10'
        option netmask '255.255.255.0'
        option broadcast '172.16.10.255'
        list dns '1.1.1.1'

config interface 'VLAN3'
        option proto 'static'
        option device 'eth0.3'
        option ipaddr '10.10.10.10'
        option netmask '255.255.255.0'
        option gateway '192.168.100.1'
        option broadcast '10.10.10.255'
        list dns '1.1.1.1'
root@OpenWrt:/# uci export dhcp
package dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'
        option ednspacket_max '1232'
        option confdir '/tmp/dnsmasq.d'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'server'
        option ra 'server'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'
root@OpenWrt:/# uci export firewall
package firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'

config zone
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        list network 'wan'
        list network 'wan6'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config rule
        option name 'Support-UDP-Traceroute'
        option src 'wan'
        option dest_port '33434:33689'
        option proto 'udp'
        option family 'ipv4'
        option target 'REJECT'
        option enabled 'false'

config include
        option path '/etc/firewall.user'
root@OpenWrt:/# head -n -0 /etc/firewall.user
# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

# Internal uci firewall chains are flushed and recreated on reload, so
# put custom rules into the root chains e.g. INPUT or FORWARD or into the
# special user chains, e.g. input_wan_rule or postrouting_lan_rule.
root@OpenWrt:/# ip -4 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: eth0.2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet 172.16.10.10/24 brd 172.16.10.255 scope global eth0.2
       valid_lft forever preferred_lft forever
5: eth0.3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet 10.10.10.10/24 brd 10.10.10.255 scope global eth0.3
       valid_lft forever preferred_lft forever
6: eth0.1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet 192.168.100.240/24 brd 192.168.100.255 scope global eth0.1
       valid_lft forever preferred_lft forever
root@OpenWrt:/# ip -4 ro li tab all
default via 192.168.100.1 dev eth0.1
10.10.10.0/24 dev eth0.3 scope link  src 10.10.10.10
172.16.10.0/24 dev eth0.2 scope link  src 172.16.10.10
192.168.100.0/24 dev eth0.1 scope link  src 192.168.100.240
broadcast 10.10.10.0 dev eth0.3 table local scope link  src 10.10.10.10
local 10.10.10.10 dev eth0.3 table local scope host  src 10.10.10.10
broadcast 10.10.10.255 dev eth0.3 table local scope link  src 10.10.10.10
broadcast 127.0.0.0 dev lo table local scope link  src 127.0.0.1
local 127.0.0.0/8 dev lo table local scope host  src 127.0.0.1
local 127.0.0.1 dev lo table local scope host  src 127.0.0.1
broadcast 127.255.255.255 dev lo table local scope link  src 127.0.0.1
broadcast 172.16.10.0 dev eth0.2 table local scope link  src 172.16.10.10
local 172.16.10.10 dev eth0.2 table local scope host  src 172.16.10.10
broadcast 172.16.10.255 dev eth0.2 table local scope link  src 172.16.10.10
broadcast 192.168.100.0 dev eth0.1 table local scope link  src 192.168.100.240
local 192.168.100.240 dev eth0.1 table local scope host  src 192.168.100.240
broadcast 192.168.100.255 dev eth0.1 table local scope link  src 192.168.100.240
root@OpenWrt:/# ip -4 ru
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default
root@OpenWrt:/# ls -l  /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*
lrwxrwxrwx    1 root     root            16 Aug 31 22:20 /etc/resolv.conf -> /tmp/resolv.conf
-rw-r--r--    1 root     root            47 Nov 16 11:39 /tmp/resolv.conf
-rw-r--r--    1 root     root           109 Nov 16 10:48 /tmp/resolv.conf.d/resolv.conf.auto

/tmp/resolv.conf.d:
-rw-r--r--    1 root     root           109 Nov 16 10:48 resolv.conf.auto
root@OpenWrt:/#  head -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*
==> /etc/resolv.conf <==
search lan
nameserver 127.0.0.1
nameserver ::1

==> /tmp/resolv.conf <==
search lan
nameserver 127.0.0.1
nameserver ::1

==> /tmp/resolv.conf.d <==
head: /tmp/resolv.conf.d: I/O error

==> /tmp/resolv.conf.d/resolv.conf.auto <==
# Interface VLAN2
nameserver 1.1.1.1
# Interface VLAN3
nameserver 1.1.1.1
# Interface lan
nameserver 1.1.1.1

so, your PC has a static IP address ... but you say you don't get IP ... perhaps the problem is on the PC then

I try static and dhcp on my pc, but the same problem I can not able to get IP.

If you set a static IP on your PC, and your PC doesn't get an IP .... something wrong with your settings on your PC

I run ipconfig in cmd, the IPv4 ADDRESS is 169.254.25.251

that's not an IP you've configured, I assume ?
It look like one it gets/self assigns if there's no DHCP....

then you've done something wrong on the PC if setting a static address gets you that thing - nothing you do on your router can fix that - except set up DHCP for your VLAN interfaces

Thank you brother it is work.

But, I have another problem. I can ping only the IPs of another Vlan and IP of router only, but I can't ping 1.1.1.1 or goes to internet.

Any help ?

I have another problem. I can ping only the IPs of another Vlan and IP of router only, but I can't ping 1.1.1.1 or goes to internet.

Any help ?

did you follow @trendy advice - i.e.